-
Notifications
You must be signed in to change notification settings - Fork 1
/
07.k
27 lines (22 loc) · 912 Bytes
/
07.k
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/--- Day 7: Some Assembly Required ---
g:{[x] $["0123456789"'*x;. x;(!W)'`$x;W`$x;()]} / get
b:{[x] ((32-#b)#0),b:2\x} / binary
w:{[x;y] $[#(),v:g@x;W[`$y]:v;()]} / wire
n:{[x;y] $[#(),v:g@x;W[`$y]:2/16 _1 0 b v;()]} / not
a:{[x;y;z] $[2=#,/v:g'(x;y);W[`$z]:2/&/b'v;()]} / and
o:{[x;y;z] $[2=#,/v:g'(x;y);W[`$z]:2/|/b'v;()]} / or
l:{[x;y;z] $[2=#,/v:g'(x;y);W[`$z]:{[x;y] 2/16 _ b[x],y#0}. v;()]} / lshift
r:{[x;y;z] $[2=#,/v:g'(x;y);W[`$z]:{[x;y] 2/(-y) _ b x}. v;()]} / rshift
f:{[x]
$[(!W)'`$last x / already solved
()
3=#x / wire
w . x 0 2
4=#x / not
n . x 1 3
((a;o;l;r)"AOLR"?x[1;0]). x 0 2 4]}
{[x;y] f'x;W}[i:" "\'0:"input/07.txt"]/:W:`!0N;
W`a
i:@[i;&(,"b")~/last'i;:;,($W`a;"->";,"b")]
{[x;y] f'x;W}[i]/:W:`!0N;
W`a