only store unique programs
This commit is contained in:
parent
7bfface1a0
commit
10abe3bf15
@ -33,6 +33,7 @@ def main
|
||||
p2.mutate
|
||||
[grade_program(p2), p2]
|
||||
end
|
||||
programs.uniq!
|
||||
programs.sort! do |a, b|
|
||||
a.first <=> b.first
|
||||
end
|
||||
|
14
program.rb
14
program.rb
@ -1,4 +1,6 @@
|
||||
class Program
|
||||
include Comparable
|
||||
|
||||
def initialize
|
||||
@instructions = []
|
||||
(2 + rand(4)).times do
|
||||
@ -60,6 +62,18 @@ class Program
|
||||
@instructions.size
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
@instructions <=> other.instance_variable_get(:@instructions)
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
(other.class == self.class) && (other == self)
|
||||
end
|
||||
|
||||
def hash
|
||||
@instructions.hash
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def random_instruction
|
||||
|
Loading…
x
Reference in New Issue
Block a user