We want to study the movement of an ant on a grid over m time steps. Think of each time step as another iteration of a loop. The grid is (2n+1)(2n+1) in size centered at (0; 0). Each grid point can be colored white or black. Initially all grid points are white. The ant is placed at (0; 0) facing toward (0; 1) at t = 0. The process is described by the following rules:
Suppose we are at t = j where 0 j m ???? 1. The ant is at (x; y) for some jxj < n and jyj < n.
1. If (x; y) is white, then it is colored black. The ant turns 90 to the left. The ant moves one step forward to the next grid point. Call it (ex; ey)
2. If (x; y) is black, then it is colored white. The ant turns 90 to the right. The ant moves one step forward to the next grid point. Call it (ex; ey).
3. j is replaced by j + 1
The process stops when either
1. t = m (time is up)
2. jexj = n (the ant is on the right or left edge)
3. jeyj = n (the ant is on the bottom or top)
The process is meant to illustrate a model for computers called a Turing machine. 1
a. Write a function called LangtonAnt with parameters n and m. The format should be function [Color; Position; Direction; t] = LangtonAnt(m,n)
Here
1. t is the time step at termination of the process. Note t <= m.
2. Color is a (2n + 1) (2n + 1) matrix indicating the color of the grid points (0 for black, 1 for white) at time t.
3. Position is the position of the ant at time t. Therefore Position is a 1 2 vector with Position(1) the x-coordinate and Position(2) the y-coordinate.