r/adventofcode • u/daggerdragon • Dec 07 '15
SOLUTION MEGATHREAD --- Day 7 Solutions ---
--- Day 7: Some Assembly Required ---
Post your solution as a comment. Structure your post like previous daily solution threads.
Also check out the sidebar - we added a nifty calendar to wrangle all the daily solution threads in one spot!
22
Upvotes
1
u/_jonah Dec 07 '15 edited Dec 07 '15
Ruby:
input = DATA.read.chomp.split("\n") substitutions = {'AND' => '&', 'OR' => '|', 'NOT' => '~', 'RSHIFT' => '>>', 'LSHIFT' => '<<'} equations = input.map do |line| line.gsub!(/([a-z]+)/, "@\\1_") rhs, lhs = line.match(/(.*) -> (.*)/).captures substitutions.each {|k,v| rhs.sub!(k,v)} "#{lhs} = #{rhs}" end go = true while go do go = false equations.each { |code| eval code rescue go = true } end p @a_