Re: Ruby Quiz - Challenge #10 - Breeding Kitties - Mix Genes Using the Sooper-Sekret Formula in the GeneSciene CryptoKitties Blockchain Contract

"Frank J. Cameron" <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
Gerald Bauer wrote:
> Challenge #10 - Breeding Kitties - Mix Genes Using the Sooper-Sekret
Formula in the GeneSciene CryptoKitties Blockchain Contract

$ ruby -v lib/010.rb
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]
Run options: --seed 48193
# Running:
.
Finished in 0.004043s, 247.3455 runs/s, 742.0366 assertions/s.

$ cat lib/010.rb
require_relative '../010/test.rb'

class RubyQuizTest
  def mixgenes(mgenes, sgenes)
    # can't resist new toys :-)
    (0..).step(4).take(12).each do |i|
      3.downto(1) do |j|
        mgenes[i+j],mgenes[i+j-1] = mgenes[i+j-1],mgenes[i+j] if rand<0.25
        sgenes[i+j],sgenes[i+j-1] = sgenes[i+j-1],sgenes[i+j] if rand<0.25
      end
    end

    48.times.map do |i|
      mutation = if i%4 == 0
        [mgenes[i], sgenes[i]].sort.then do |tg|
          if tg[1] - tg[0] == 1 and tg[0].even?
            tg[0] / 2 + 16 if rand < (tg[0] > 23 ? 0.125 : 0.25)
          end
        end
      end

      mutation or rand < 0.5 ? mgenes[i] : sgenes[i]
    end
  end
end

RubyQuizTest.new('fjc')



Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.