Write a program that takes a random walk on NxN grid. The walker should do the following:
For instance, suppose that the sequence of moves is:
- Walk on a 10x10 grid
- Start at the position 5, 5
- Never move to a position it has occupied previously
- Never move off the grid
- Determine the set of legal moves from the current position. Legal moves are one space, either up, down, right or left AND that do not violate either of the preceding conditions.
- Print each move made on a single line. This may be as simple as "23 [3,2]" which would mean that on move 23 the walker was in position 3,2
- Move randomly from among the legal moves.
- Return the number of steps it takes before the walker gets to a point of having no legal moves.
Then at this point there are no remaining legal moves since the walker has already been to every position possible from [6,6]. Hence, program (or function) should return 8. In fact 8 moves is the shortest walk possible (on a 10x10 board) given the rules above.