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