Langton's ant: Difference between revisions

→‎{{header|APL}}: Add implementation
(→‎{{header|UNIX Shell}}: Add implementation)
(→‎{{header|APL}}: Add implementation)
Line 499:
##
</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
<syntaxhighlight lang="apl">langton ← {⍺←⍵ ⋄ grid←⍺ ⍵⍴0 ⋄ ant←2÷⍨⍺ ⍵ ⋄ dir←?4 ⋄ grid ant dir}
step ← {
grid ant dir←⍵
dir←1+4|dir+2×grid[⊂ant]
grid[⊂ant]←1-grid[⊂ant]
ant+←(4 2⍴0 ¯1 1 0 0 1 ¯1 0)[dir;]
grid ant dir
}
⍝ to watch it run, open the variable pic in the monitor before executing this step
{} { state ∘← ⍵ ⋄ pic ∘← '.⌺'[1+⊃1⌷⍵] ⋄ _←⎕dl ÷500 ⋄ step ⍵} ⍣≡ langton 100</syntaxhighlight>
 
{{Out}}
The final contents of <tt>pic</tt> (eliding leading and trailing blank lines)
<pre>......................................⌺⌺..⌺⌺⌺⌺⌺⌺⌺⌺⌺⌺⌺⌺..⌺⌺..........................................
.....................................⌺⌺..⌺..........⌺⌺⌺⌺..⌺.........................................
....................................⌺.⌺⌺............⌺⌺...⌺⌺⌺........................................
....................................⌺....⌺..⌺.........⌺..⌺.⌺........................................
..................................⌺.......⌺⌺⌺.........⌺.⌺.⌺⌺..⌺⌺....................................
..................................⌺⌺⌺..⌺⌺.⌺⌺.....⌺.....⌺...⌺..⌺.⌺⌺⌺.................................
..............................⌺⌺..⌺⌺.⌺..⌺.⌺...⌺⌺.⌺⌺⌺⌺.⌺⌺..⌺⌺⌺..⌺.⌺..................................
.............................⌺⌺⌺...⌺⌺⌺.....⌺.⌺.⌺⌺⌺..⌺⌺.⌺..⌺⌺.⌺⌺⌺.⌺..................................
............................⌺.⌺.⌺.⌺⌺⌺...⌺..⌺⌺⌺⌺..⌺.⌺.⌺⌺⌺⌺⌺...⌺.....⌺................................
............................⌺...⌺.⌺⌺⌺.⌺.⌺⌺⌺⌺⌺⌺.⌺⌺.⌺⌺..⌺⌺⌺⌺.⌺...⌺⌺.⌺⌺⌺...............................
.............................⌺⌺.⌺⌺⌺.⌺⌺⌺⌺⌺...⌺.⌺⌺.⌺⌺.⌺⌺.⌺.⌺.⌺⌺.⌺.⌺⌺⌺.⌺...............................
...........................⌺⌺.⌺....⌺⌺⌺⌺..⌺.⌺...⌺...⌺⌺⌺.⌺⌺.⌺...⌺.⌺...................................
..........................⌺⌺.....⌺.⌺⌺.....⌺⌺..⌺...⌺⌺.⌺⌺.........⌺..⌺................................
.........................⌺.⌺⌺..⌺⌺.⌺⌺⌺...⌺.....⌺⌺..⌺..⌺⌺⌺.⌺⌺.⌺.⌺...⌺⌺⌺...............................
.........................⌺...⌺⌺⌺⌺.⌺⌺..⌺....⌺..⌺⌺⌺...⌺⌺.⌺⌺...⌺⌺..⌺⌺⌺..⌺..............................
..........................⌺.....⌺..⌺⌺⌺.⌺⌺.⌺..⌺⌺.⌺⌺⌺⌺.⌺.⌺..⌺.⌺...⌺...⌺⌺⌺.............................
........................⌺⌺..⌺..⌺.⌺⌺.⌺⌺⌺......⌺..⌺⌺⌺.⌺..⌺....⌺⌺.⌺..⌺⌺⌺..⌺............................
.......................⌺...⌺⌺.⌺⌺⌺⌺..⌺⌺⌺⌺.⌺⌺⌺⌺⌺..⌺⌺..⌺⌺.⌺.⌺⌺.⌺.....⌺...⌺⌺⌺...........................
......................⌺...⌺....⌺.⌺.⌺...⌺⌺......⌺⌺.⌺.⌺.⌺⌺⌺.⌺..⌺.⌺.⌺..⌺⌺⌺..⌺..........................
......................⌺......⌺...⌺⌺⌺⌺.⌺⌺⌺⌺.......⌺⌺...⌺.⌺⌺..⌺⌺⌺.⌺⌺..⌺...⌺⌺⌺.........................
.......................⌺....⌺....⌺..⌺⌺⌺⌺..⌺.⌺⌺⌺⌺⌺⌺⌺⌺⌺⌺⌺..⌺⌺...⌺..⌺.⌺..⌺⌺⌺..⌺........................
.......................⌺⌺..⌺....⌺⌺..⌺..⌺⌺⌺⌺⌺⌺⌺⌺⌺..⌺⌺..⌺⌺⌺⌺.⌺......⌺⌺..⌺...⌺⌺⌺.......................
......................⌺.⌺⌺⌺⌺..⌺⌺.⌺..⌺...⌺⌺⌺.⌺⌺⌺.⌺⌺.⌺⌺...⌺⌺.⌺..⌺⌺...⌺.⌺..⌺⌺⌺..⌺......................
......................⌺...⌺⌺...⌺⌺⌺.⌺⌺⌺....⌺.⌺.⌺⌺.⌺.⌺⌺.⌺⌺⌺⌺⌺⌺.⌺..⌺...⌺⌺..⌺...⌺⌺⌺.....................
.......................⌺...⌺⌺....⌺.⌺⌺..⌺.⌺.....⌺⌺⌺⌺⌺.⌺.⌺⌺⌺⌺⌺.....⌺...⌺.⌺..⌺⌺⌺..⌺....................
.......................⌺..⌺..⌺.⌺⌺..⌺..⌺...⌺.⌺..⌺⌺.⌺⌺⌺⌺⌺.⌺⌺.⌺.....⌺....⌺⌺..⌺...⌺⌺⌺...................
.......................⌺⌺...⌺⌺⌺⌺⌺⌺⌺⌺⌺⌺...⌺⌺.⌺⌺⌺⌺⌺..⌺.⌺⌺⌺⌺...⌺....⌺.....⌺.⌺..⌺⌺⌺..⌺..................
...........................⌺⌺.⌺⌺⌺⌺.⌺⌺...⌺..⌺⌺⌺⌺...⌺..⌺...⌺⌺...⌺⌺.⌺......⌺⌺..⌺...⌺⌺⌺.................
.........................⌺.⌺..⌺..⌺..⌺.⌺....⌺...⌺.⌺⌺...⌺⌺..⌺.⌺⌺⌺⌺⌺........⌺.⌺..⌺⌺⌺..⌺................
.........................⌺⌺..⌺⌺..⌺..⌺⌺.⌺.⌺.⌺⌺.⌺⌺....⌺.⌺.⌺.⌺⌺..⌺⌺..........⌺⌺..⌺...⌺⌺⌺...............
.........................⌺.⌺⌺⌺⌺..⌺⌺.⌺.⌺.⌺⌺⌺⌺⌺⌺⌺⌺.⌺....⌺..⌺.................⌺.⌺..⌺⌺⌺..⌺..............
.........................⌺.⌺⌺..⌺..⌺...⌺⌺.⌺⌺.......⌺...⌺..⌺..................⌺⌺..⌺...⌺⌺⌺.............
.........................⌺⌺⌺⌺.⌺⌺...⌺⌺..⌺⌺..⌺......⌺..⌺..⌺....................⌺.⌺..⌺⌺⌺..⌺............
........................⌺⌺⌺.⌺...⌺....⌺⌺..⌺⌺.......⌺...⌺⌺......................⌺⌺..⌺...⌺⌺⌺...........
........................⌺⌺⌺⌺.⌺⌺⌺.⌺⌺⌺⌺....⌺⌺⌺⌺..⌺⌺.⌺............................⌺.⌺..⌺⌺⌺..⌺..........
.......................⌺..⌺.⌺.⌺⌺.⌺..⌺⌺....⌺⌺⌺⌺..⌺⌺..............................⌺⌺..⌺...⌺⌺⌺.........
......................⌺⌺⌺⌺⌺.⌺⌺.⌺⌺⌺.⌺⌺....⌺⌺....⌺⌺................................⌺.⌺..⌺⌺⌺..⌺........
......................⌺⌺⌺⌺..⌺.⌺⌺.⌺................................................⌺⌺..⌺...⌺⌺⌺.......
......................⌺⌺.⌺⌺.⌺⌺.....................................................⌺.⌺..⌺⌺⌺..⌺......
............................⌺⌺......................................................⌺⌺..⌺...⌺⌺⌺.....
....................⌺.⌺⌺⌺⌺..⌺⌺.⌺.....................................................⌺.⌺..⌺⌺⌺..⌺....
....................⌺⌺⌺..⌺⌺⌺.⌺..⌺.....................................................⌺⌺..⌺...⌺⌺⌺...
.....................⌺..⌺..⌺.⌺⌺.⌺......................................................⌺.⌺..⌺⌺⌺..⌺..
......................⌺⌺......⌺⌺........................................................⌺⌺..⌺...⌺⌺⌺.
.............................⌺⌺..........................................................⌺.⌺..⌺⌺⌺..⌺
..........................................................................................⌺⌺..⌺.⌺⌺⌺.
...........................................................................................⌺.⌺.⌺.⌺.⌺
............................................................................................⌺⌺.⌺⌺⌺⌺.
.............................................................................................⌺.⌺⌺.⌺.
..............................................................................................⌺⌺⌺⌺..
...............................................................................................⌺⌺...</pre>
 
=={{header|AutoHotkey}}==
1,480

edits