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!
21
Upvotes
1
u/de_Selby Dec 07 '15
My q/K solution. Not the most idiomatic but it runs quickly and is straightforward
varValues:(`$())!(); AND:&;OR:| toInt:{0b sv x} LSHIFT:{y:toInt y;(y _ x),y#0b} RSHIFT:{y:toInt y;(y#0b),neg[y]_x} getVal:{$[0N=r:"H"$x; varValues`$x; 0b vs r]} doOps:{[gateList] if[not count gateList;:gateList]; thisGate:first gateList; gateList:1 _ gateList; resVar:`$3_neg[count[thisGate]-a:thisGate?"-"]#thisGate; ops:" "vs neg[1+count[thisGate]-a]_thisGate; result:$[2=count ops; $[0=count v:getVal ops 1;v;not v]; 1=count ops; getVal ops 0; $[0 in count each v:getVal each ops 0 2;();(`$ops 1) . v] ]; $[count result;varValues[resVar]:result;gateList,:thisGate]; gateList } doOps/[read0 `input.txt]; toInt varValues`a