This commit is contained in:
josh committed 2014-02-10 21:47:11 -05:00
commit 78b45a84cc
2 files changed
+36

No files matched your search

Executable
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
require_relative "program"
+33
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