Skip to content

Instantly share code, notes, and snippets.

@epitron
Created December 7, 2015 05:46
Show Gist options
  • Save epitron/1f3876caacfb6d4ac72b to your computer and use it in GitHub Desktop.
Save epitron/1f3876caacfb6d4ac72b to your computer and use it in GitHub Desktop.
require 'pry'
class Circuit
TRANSFORMS = {
"LSHIFT" => "<<",
"RSHIFT" => ">>",
"NOT" => "~",
"AND" => "&",
"OR" => "|",
/\b(if|do|in)\b/ => "\\1_",
}
def add(line)
TRANSFORMS.each do |from, to|
line.gsub!(from, to)
end
expr, name = line.strip.split(" -> ")
method = "def #{name}; @#{name} ||= #{expr}; end"
puts method
instance_eval method
end
end
circuit = Circuit.new
open("advent7.txt").each_line { |line| circuit.add(line) }
# circuit.add("46065 -> b")
p circuit.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment