Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

LiddleLizzard - a digital organism

View liddle_lizzard.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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.