initial
This commit is contained in:
commit
78b45a84cc
3
genetic.rb
Executable file
3
genetic.rb
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative "program"
|
33
program.rb
Normal file
33
program.rb
Normal 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
|
Loading…
x
Reference in New Issue
Block a user