only store unique programs

This commit is contained in:
josh committed 2014-02-11 09:34:59 -05:00
1 parent 7bfface1a0
commit 10abe3bf15
2 files changed
+15

No files matched your search

+1
View File
@@ -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
View File
@@ -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