Skip to content

Instantly share code, notes, and snippets.

@Poincare
Created July 5, 2012 19:04
Show Gist options
  • Select an option

  • Save Poincare/3055730 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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

@Poincare

Poincare commented Jul 19, 2012 via email

Copy link
Copy Markdown
Author

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