Langton's ant: Difference between revisions
Content added Content deleted
(→{{header|APL}}: Correct coordinate chirality) |
m (→{{header|APL}}: Formatting) |
||
Line 503: | Line 503: | ||
{{works with|Dyalog APL}} |
{{works with|Dyalog APL}} |
||
<syntaxhighlight lang="apl">langton ← {⍺←⍵ ⋄ grid←⍺ ⍵⍴0 ⋄ ant←2÷⍨⍺ ⍵ ⋄ dir←?4 ⋄ grid ant dir} |
<syntaxhighlight lang="apl">langton ← {⍺←⍵ ⋄ grid←⍺ ⍵⍴0 ⋄ ant←2÷⍨⍺ ⍵ ⋄ dir←?4 ⋄ grid ant dir} |
||
step ← { |
|||
grid ant dir←⍵ |
|||
dir←1+4|dir+2×grid[⊂ant] |
|||
dir←1+4|dir+2×grid[⊂ant] |
|||
grid[⊂ant]←1-grid[⊂ant] |
|||
⍝ coordinates are matrix order: row,col. So up is -1 0, right is 0 1, down is 1 0, and left is 0 -1 |
|||
⍝ coordinates are matrix order: row,col. So up is -1 0, right is 0 1, down is 1 0, and left is 0 -1 |
|||
ant+←(4 2⍴¯1 0 0 1 1 0 0 ¯1)[dir;] |
|||
grid ant dir |
|||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{{Out}} |
{{Out}} |