Langton's ant: Difference between revisions
Content added Content deleted
(→{{header|UNIX Shell}}: Add implementation) |
(→{{header|APL}}: Add implementation) |
||
Line 499: | Line 499: | ||
## |
## |
||
</pre> |
</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}}== |
=={{header|AutoHotkey}}== |