Langton's ant: Difference between revisions

m
(→‎{{header|APL}}: Add comments)
Line 507:
⍝ If rows not specified, set equal to columns
⍺ ← ⍵
 
⍝ 0=white, 1=black. Start with all white
grid ← ⍺ ⍵ ⍴ 0
 
⍝ Start the ant in the middle
ant ← 2 ÷⍨ ⍺ ⍵
 
⍝ Aimed inain a random direction
dir ← ?4
 
⍝ return everything in a tuple
grid ant dir
Line 524 ⟶ 528:
dir ← 1 + 4|dir+2×grid[⊂ant]
 
⍝ Toggle cell coloercolor
grid[⊂ant]←1 ← 1 - grid[⊂ant]
 
⍝ Advance along dir. Since coordinates are matrix order (row,col),
⍝ up is -1 0, right is 0 1, down is 1 0, and left is 0 -1
ant +← (4 2⍴2 ⍴ ¯1 0, 0 1, 1 0, 0 ¯1)[dir;]
grid ant dir
}
1,479

edits