-
Notifications
You must be signed in to change notification settings - Fork 1
/
11.q
65 lines (58 loc) · 1.22 KB
/
11.q
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//--- Day 11: Space Police ---
\l 09.q
f:{[i;p]
if[9 9~2#ii:reverse (5#10) vs i p;
:()
];
a:i p + 1 + til A o:first ii;
if[3=o;
STDIN::0^PANELS LOC;
];
if[not o=3;
a[w]:i a w:where 0=B[o]#2_ii;
a[w]:i BASE + a w:where 2=B[o]#2_ii
if[2=ii 4;
a[2]:BASE + a 2
];
];
if[1<count r:(O o). a;
i[r 1]:r 2
];
if[o=4;
$[MOVE::not MOVE;
LOC+:(0 1;0 -1;-1 0;1 0)"UDLR"?DIR::$[STDOUT;"RLUD";"LRDU"]"UDLR"?DIR;
PANELS[LOC]:STDOUT
];
];
p:$[null first r;
p + 1 + A o;
first r];
enlist (i;p)
};
g:{[i;loc;col]
QUEUE:enlist(i;0);
STDOUT::0N;
BASE::0;
LOC::loc;
DIR::"U";
PANELS::(`u#enlist loc)!enlist col;
MOVE::1b;
while[count QUEUE;
ip:first QUEUE;
QUEUE:1_QUEUE;
QUEUE,:f[first ip;last ip]
]
};
I:"J"$"," vs first read0 `:input/11.txt
g[I;0 0;0];
count PANELS
/1686
g[I,1000#0;0 5;1];
OUT:{.[x;y;:;"@"]}/[(1+max each flip key PANELS)#" ";where PANELS];
-1@reverse flip OUT;
/ @@ @@ @@@ @@@ @ @ @@@@ @ @ @
/ @ @ @ @ @ @ @ @ @ @ @ @ @ @
/ @ @ @ @ @ @ @ @@ @ @ @ @
/ @ @@ @@@@ @@@ @@@ @ @ @ @ @ @
/ @ @ @ @ @ @ @ @ @ @ @ @ @
/ @@@ @ @ @ @ @ @ @ @@@@ @@ @@@@