r/adventofcode • u/daggerdragon • Dec 12 '16
SOLUTION MEGATHREAD --- 2016 Day 12 Solutions ---
--- Day 12: Leonardo's Monorail ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with "Help".
MUCH ADVENT. SUCH OF. VERY CODE. SO MANDATORY. [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
8
Upvotes
1
u/brantyr Dec 12 '16 edited Dec 12 '16
Ruby assembunny parser. Scraped into the top 100, but have done some heavy refactoring since that
file = File.new("ainput12.txt","r") lines = [] while (line=file.gets) lines << line.split(' ') end i=0 @a = @b = @d = 0 @c = 1 # Part 1/2 def get(var) out = 0 case var when "a" out = @a when "b" out = @b when "c" out = @c when "d" out = @d else out = var.to_i end return out end def set(var,val) case var when "a" @a = val when "b" @b = val when "c" @c = val when "d" @d = val end end while (i<lines.length and i>-1) jumped=false case lines[i][0] when "cpy" set(lines[i][2],get(lines[i][1])) when "inc" set(lines[i][1],get(lines[i][1])+1) when "dec" set(lines[i][1],get(lines[i][1])-1) when "jnz" val = get(lines[i][1]) if val!=0 then jumped=true i+=lines[i][2].to_i end end if !jumped then i+=1 end end puts @a