An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially.
At each step, it does the following:
(1) At a white square, flip the color of the square, turn 90 degrees right (clockwise), and move forward one unit.
(2) At a black square, flip the color of the square, turn 90 degrees left (counter-clockwise), and move forward one unit.
Write a program to simulate the first K moves that the ant makes and print the final board as a grid.
The grid should be represented as an array of strings, where each element represents one row in the grid. The black square is represented as 'X'
, and the white square is represented as '_'
, the square which is occupied by the ant is represented as 'L'
, 'U'
, 'R'
, 'D'
, which means the left, up, right and down orientations respectively. You only need to return the minimum matrix that is able to contain all squares that are passed through by the ant.
Example 1:
Input: 0
Output: ["R"]
Example 2:
Input: 2
Output:
[
"_X",
"LX"
]
Example 3:
Input: 5
Output:
[
"_U",
"X_",
"XX"
]
Note:
K <= 100000