Langton's ant: Difference between revisions
m
→{{header|APL}}
(→{{header|APL}}: Add comments) |
m (→{{header|APL}}) |
||
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
dir ← ?4
⍝ return everything in a tuple
grid ant dir
Line 524 ⟶ 528:
dir ← 1 + 4|dir+2×grid[⊂ant]
⍝ Toggle cell
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
grid ant dir
}
|