Skip to content

Instantly share code, notes, and snippets.

@Poincare
Created July 20, 2012 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Poincare/3151534 to your computer and use it in GitHub Desktop.
Save Poincare/3151534 to your computer and use it in GitHub Desktop.
class Chromosome
...
def self.produce_new(chrs)
roulette(chrs)
newchrs = []
chrs.each do |c|
newchrs.push(roulette(chrs))
end
fitnesses(newchrs)
return newchrs
end
...
@msimcoe
Copy link

msimcoe commented Feb 9, 2016

The code as written in gistfile1.rb produced 2 errors when I tried to run it using v2.3.0. The first is on line 5. I had to add to_i as follows:
def fitness
@Fitness = @bitstring.to_i^0b0101
end

The second is on line 100 which reads: chrs = Chromosome.produce_new(chrs). This had to be changed to: chrs = Chromosome.produceNew(chrs), to match the definition of self.produceNew(chrs).

All in all I really enjoyed the articles. I'm am learning Ruby as a first language (not counting fortran in college) and I want to also learn how to program algorithms. I'm looking forward to your follow on article to Graph Algorithms in Ruby. I think it should be very interesting. Thank you very much for taking the time write the articles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment