29 lines
848 B
Text
29 lines
848 B
Text
!YS-v0
|
|
|
|
defn main(steps=511):
|
|
data [minx maxx miny maxy] =:
|
|
loop i 0 [x y], [0 0], data {}, [minx maxx miny maxy] [0 0 0 0]:
|
|
dir =: i-to-dir(i)
|
|
nx ny =: +
|
|
[(x + condp(== dir 0 1 2 -1 0))
|
|
(y + condp(== dir 1 1 3 -1 0))]
|
|
ob ib =: dir.nth([[8 4][2 1][4 8][1 2]])
|
|
data =: update-in(data [y x] safe-bit-or ob)
|
|
.update-in([ny nx] safe-bit-or ib)
|
|
bbox =: +
|
|
[min(minx nx) max(maxx nx)
|
|
min(miny ny) max(maxy ny)]
|
|
if i < steps:
|
|
recur: i.++, [nx ny], data, bbox
|
|
vector: data bbox
|
|
|
|
each y (miny .. maxy):
|
|
say: !:join
|
|
each x (minx .. maxx):
|
|
get-in(data [y x] 0).nth(" ╵╷│╴┘┐┤╶└┌├─┴┬┼")
|
|
|
|
defn i-to-dir(n):
|
|
n.bit-xor(bit-shift-right(n 1)):Long/bitCount % 4
|
|
|
|
defn safe-bit-or(v bit):
|
|
(v || 0).bit-or(bit)
|