Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
29
Task/Dragon-curve/YAMLScript/dragon-curve.ys
Normal file
29
Task/Dragon-curve/YAMLScript/dragon-curve.ys
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
!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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue