Skip to content

Instantly share code, notes, and snippets.

@Poincare
Created July 5, 2012 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Poincare/3055730 to your computer and use it in GitHub Desktop.
Save Poincare/3055730 to your computer and use it in GitHub Desktop.
class Chromosome
attr_accessor :bitstring
attr_accessor :fitness
def generate_random(length)
i = 0
@bitstring = ""
while i < length
@bitstring += rand(2).to_s
i += 1
end
end
def self.get_random_chromosomes(length, number)
i = 0
res = []
while i < number
res.push(Chromosome.new(length))
i += 1
end
setFitnesses(res)
return res
end
def initialize(length, bitString = nil)
@length = length
if bitString == nil
generate_random(length)
else
@bitstring = bitString
end
end
end
@havenwood
Copy link

Did a quick refactor, trying to make it more idiomatic Ruby: https://gist.github.com/3145912

@Poincare
Copy link
Author

Poincare commented Jul 19, 2012 via email

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