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
View all comments
Show parent comment
2
u/Smylers Dec 12 '16 edited Dec 12 '16
A better Perl solution: only parse the input once, turning each line into a closure which performs the appropriate operation and then returns the new program counter offset. Then just set the closures running and see what happens:
Apart from anything else, it's ~14 times quicker at part 2 than the above, making it quick enough to avoid any halting-problemesque ‘is it getting there slowly or is it stuck in a loop’ quandries while running it.
But mainly I like it more for not having to parse the input lines multiple times, the simplicity of the main
whileloop (a single line), and the general neatness of an array of single-instruction closures combining together.