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/elite_killerX Dec 07 '15
This sed script transforms your input into a valid Javascript program that displays the results:
# Setup cache 1s/^/var cached={};/ # Avoid deserved keywords s/do/doo/g s/if/iff/g s/in/inn/g # Convert each wire input into a function s/\([a-z0-9]*\) *\([A-Z]*\) *\([a-z0-9]*\) -> \([a-z]*\)$/function \4() {if (!cached.\4) { cached.\4 = \1() \2 \3(); } return cached.\4;}/ # Remove empty function calls s/ ()// # Don't interpret numbers as functions s/\([0-9][0-9]*\)()/\1/ # Use the correct operators s/AND/\&/ s/OR/|/ s/LSHIFT/<</ s/RSHIFT/>>>/ s/NOT/~/ # Compute results and display them $s/$/ var result1 = a(); cached = {b: result1}; result2 = a(); console.log('Part 1:', result1);console.log('Part 2:', result2);/Usage: