Created
December 7, 2015 05:46
-
-
Save epitron/1f3876caacfb6d4ac72b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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