Spiral matrix: Difference between revisions

Added Quackery.
m (→‎Iterative Solution: Improved syntax.)
(Added Quackery.)
Line 4,117:
14 23 22 21 8
13 12 11 10 9</lang>
 
=={{header|Quackery}}==
 
There's more about the section marked <code>( turtle draws spiral )</code> in the [[Talk:Spiral_matrix#As_an_exercise_in_Turtle_Graphics.|Talk page]].
 
<lang Quackery> [ stack ] is stepcount ( --> s )
[ stack ] is position ( --> s )
[ stack ] is heading ( --> s )
[ heading take
behead join
heading put ] is right ( --> )
[ times
[ position share
stepcount share
unrot poke
1 stepcount tally
heading share 0 peek
position tally ] ] 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 join
-1 join over negate join
heading put
0 over dup * of
over 1 - walk right ( turtle draws spiral )
over 1 - times
[ i 1+ walk right
i 1+ walk right ]
1 walk
matrixify ( ...tidy up )
heading release
position release
stepcount release ] is spiral ( n --> [ )
 
9 spiral
witheach
[ witheach
[ dup 10 < if sp echo sp ]
cr ]</lang>
 
{{out}}
 
<pre> 0 1 2 3 4 5 6 7 8
31 32 33 34 35 36 37 38 9
30 55 56 57 58 59 60 39 10
29 54 71 72 73 74 61 40 11
28 53 70 79 80 75 62 41 12
27 52 69 78 77 76 63 42 13
26 51 68 67 66 65 64 43 14
25 50 49 48 47 46 45 44 15
24 23 22 21 20 19 18 17 16</pre>
 
=={{header|R}}==
1,462

edits