Draw the path of Langton's ant.
Description
Squares on a plane are colored variously either black or white. We arbitrarily identify one square as the "ant". The ant can travel in any of the four cardinal directions at each step it takes. The ant moves according to the rules below:
- At a white square, turn 90° right, flip the color of the square, move forward one unit
- At a black square, turn 90° left, flip the color of the square, move forward one unit
Specifications
- Input: an integer N between 0 and 725 (inclusive).
- Output: a 17 by 17 grid representing the "path" of the ant as of step N.
Rules
- The ant starts facing right (3 o' clock).
- The ant starts at the center of the grid.
- Use
_#@
for white squares, black squares and the ant respectively. - The grid is initially completely white.
- You may make either a complete program or a function on an interpreted language.
- Input by stdin or argument.
Examples
Update: case's N = 450 output was wrong.
N = 0
_________________
_________________
_________________
_________________
_________________
_________________
_________________
_________________
________@________
_________________
_________________
_________________
_________________
_________________
_________________
_________________
_________________
N = 1
_________________
_________________
_________________
_________________
_________________
_________________
_________________
_________________
________#________
________@________
_________________
_________________
_________________
_________________
_________________
_________________
_________________
N = 450
_________________
_________________
___________##____
____##______##___
___#__##___##_#__
__###_#@#__#__#__
__#_#_#_#__#_#___
_____###___#_____
_____#___________
_____#__###______
___#_#_#__#_#_#__
__#__#_#____###__
__#_##__##___#___
___##______##____
____##___________
_________________
_________________