Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
LiddleLizzard - a digital organism
class LiddleLizzard
CHROMOSOME_LENGTH = 500
include Comparable
attr_accessor :chromosome
def initialize
@chromosome = BitString.new(CHROMOSOME_LENGTH).bit_string
end
def <=>(other)
self.fitness <=> other.fitness
end
# calculates the "fitness" of this chromosome
def fitness
score = 0
chromosome.scan(/1*/).each do |str|
score = str.length if str.length > score
end
score
end
# mutates this chromosome
def mutate
chromosome[rand(500)-1] = '1'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.