This commit is contained in:
Josh Holtrop 2014-02-10 21:47:11 -05:00
commit 78b45a84cc
2 changed files with 36 additions and 0 deletions

3
genetic.rb Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env ruby
require_relative "program"

33
program.rb Normal file
View File

@ -0,0 +1,33 @@
class Program
def initialize
@instructions = []
(2 + rand(4)).times do
@instructions << random_instruction
end
end
private
def random_instruction
case rand(2)
when 0
[:load, (65 + rand(26)).chr]
when 1
[:output]
end
end
def to_s
@instructions.map do |instruction, *params|
case instruction
when :load
"load #{params.first.inspect}"
when :output
"output"
end
end.join("\n")
end
def execute
end
end