From 78b45a84cce22ed507dddfda5d4ffbdf23a9a2d9 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 10 Feb 2014 21:47:11 -0500 Subject: [PATCH] initial --- genetic.rb | 3 +++ program.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 genetic.rb create mode 100644 program.rb 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