commit 78b45a84cce22ed507dddfda5d4ffbdf23a9a2d9 Author: Josh Holtrop Date: Mon Feb 10 21:47:11 2014 -0500 initial diff --git a/genetic.rb b/genetic.rb new file mode 100755 index 0000000..550f21f --- /dev/null +++ b/genetic.rb @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby + +require_relative "program" diff --git a/program.rb b/program.rb new file mode 100644 index 0000000..0556b8e --- /dev/null +++ b/program.rb @@ -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