Skip to content

Commit afe7eee

Browse files
committed
blog: Improve code for Dragon curve
1 parent 88a8a6a commit afe7eee

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

blog/2025-07-18.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,20 @@ defn main(steps=511):
113113
nx ny =: +
114114
[(x + condp(== dir 0 1 2 -1 0))
115115
(y + condp(== dir 1 1 3 -1 0))]
116-
ob ib =: nth([[8 4][2 1][4 8][1 2]] dir)
116+
ob ib =: dir.nth([[8 4][2 1][4 8][1 2]])
117117
data =: update-in(data [y x] safe-bit-or ob)
118118
.update-in([ny nx] safe-bit-or ib)
119119
bbox =: +
120120
[min(minx nx) max(maxx nx)
121121
min(miny ny) max(maxy ny)]
122122
if i < steps:
123-
recur: i.++ [nx ny] data bbox
123+
recur: i.++, [nx ny], data, bbox
124124
vector: data bbox
125125

126-
doseq y (range miny maxy.++):
127-
chars =:
128-
for x (range minx maxx.++):
129-
nth(" ╵╷│╴┘┐┤╶└┌├─┴┬┼" get-in(data [y x] 0))
130-
say: str(chars*)
126+
each y (miny .. maxy):
127+
say: !:join
128+
each x (minx .. maxx):
129+
get-in(data [y x] 0).nth(" ╵╷│╴┘┐┤╶└┌├─┴┬┼")
131130

132131
defn i-to-dir(n):
133132
n.bit-xor(bit-shift-right(n 1)):Long/bitCount % 4

0 commit comments

Comments
 (0)