This kata is based on Project Euler Problem #349. You may want to start with solving this kata first.
Langton's ant moves on a regular grid of squares that are coloured either black or white. The ant is always oriented in one of the cardinal directions (left, right, up or down) and moves according to the following rules:
- if it is on a black square, it flips the colour of the square to white, rotates 90 degrees counterclockwise and moves forward one square.
- if it is on a white square, it flips the colour of the square to black, rotates 90 degrees clockwise and moves forward one square.
Starting with a grid that is entirely white, how many squares are black after n
moves of the ant?
Note: n
will go as high as 1020
If you enjoyed this kata then please try my other katas! :-)