Zig-zag matrix: Difference between revisions

→‎{{header|Quackery}}: added turtle style solution
(→‎{{header|AppleScript}}: Added a faster version of one of the existing iterative scripts.)
(→‎{{header|Quackery}}: added turtle style solution)
Line 5,291:
 
=={{header|Quackery}}==
 
===Sorting Indices===
 
{{trans|Python:_By_sorting_indices}}
 
 
<lang Quackery> [ ]'[ tuck do dip do ] is with2 ( x x --> x x )
Line 5,323 ⟶ 5,326:
[ dup 10 < if sp
echo sp ]
cr ]</lang>
 
{{out}}
 
<pre> 0 1 5 6 14 15 27 28 44 45
2 4 7 13 16 26 29 43 46 63
3 8 12 17 25 30 42 47 62 64
9 11 18 24 31 41 48 61 65 78
10 19 23 32 40 49 60 66 77 79
20 22 33 39 50 59 67 76 80 89
21 34 38 51 58 68 75 81 88 90
35 37 52 57 69 74 82 87 91 96
36 53 56 70 73 83 86 92 95 97
54 55 71 72 84 85 93 94 98 99
</pre>
 
===Turtle style===
 
Adapted from [[Spiral matrix#Quackery]]
 
The sequence of turns for the first half of the matrix is east to southwest to south to northeast to east. In the second half the order of turns is reversed.
 
 
<lang Quackery> [ stack ] is stepcount ( --> s )
[ stack ] is position ( --> s )
[ stack ] is heading ( --> s )
 
[ heading take
behead join
heading put ] is turn ( --> )
 
[ heading share 0 peek
unrot times
[ position share
stepcount share
unrot poke
over position tally
1 stepcount tally ]
nip ] is walk ( [ n --> [ )
 
[ dip [ temp put [] ]
temp share times
[ temp share split
dip
[ nested join ] ]
drop temp release ] is matrixify ( n [ --> [ )
 
[ 0 stepcount put ( set up... )
0 position put
' [ 1 ]
over 1 - join
over join
over 1 - negate join
heading put
0 over dup * of
over 1 - times ( turtle draws first half of zigzag )
[ 1 walk turn
i^ 1+ walk turn ]
heading take ( reverse the sequence of turns )
reverse heading put
over 1 - times ( turtle draws second half of zigzag )
[ turn 1 walk
turn i walk ]
1 walk
matrixify ( ...tidy up )
heading release
position release
stepcount release ] is zigzag ( n --> [ )
 
10 zigzag
witheach
[ witheach
[ dup 10 < if sp echo sp ]
cr ]</lang>
 
1,462

edits