12 8
1234321
....#.......
........#...
...........#
...#O.......
...#........
.......#....
...........#
....#.......
For example: hereβs a testcase I cannot pass, because Iβm off by 1 step. I donβt include the vector back to start. But if I include these vectors Iβll pass these two cases but fail the infinite loop cases.
These are my cached results of visited nodes. The r,c,and direction or move index and the step. When the robot turns it will not increment the step.
{
β3,4,0β: 0,
β2,4,0β: 1,
β1,4,0β: 2,
β1,4,1β: 2,
β1,5,1β: 3,
β1,6,1β: 4,
β1,7,1β: 5,
β1,7,2β: 5,
β2,7,2β: 6,
β3,7,2β: 7,
β4,7,2β: 8,
β4,7,3β: 8,
β4,6,3β: 9,
β4,5,3β: 10,
β4,4,3β: 11,
β4,4,0β: 11
}
n = 1234309 totalsteps = 11
1234309 % 11 = 10 additional steps which is incorrect because I'm not including that last vector.
n = 1234309 totalsteps = 12 (including that last vector as a step even though I've traversed it already)
1234309 % 12 = 1 additional step. which is correct which ends up landing me in row 2, col 4 or answer 4 2.
When I do find a loop I would just make the robot remain in position and modulus the n by the total steps of the loop. This may be whatβs incorrect(?), but I donβt think so. I believe this is correct logic in just having the robot stay in place, mod n by total steps so we can find out what remaining steps need to be taking by the robot.
Hereβs the infinite loop case where I do pass by not including the last traveled vector to a loop.
12 6
4000000000
..##..#.....
...........#
............
............
.#.O........
..........#.
The last vector that I do not include is at 1,3,1 and that gives me the proper mod value.
{
β4,3,0β: 0,
β3,3,0β: 1,
β2,3,0β: 2,
β1,3,0β: 3,
β1,3,1β: 3,
β1,4,1β: 4,
β1,5,1β: 5,
β1,6,1β: 6,
β1,7,1β: 7,
β1,8,1β: 8,
β1,9,1β: 9,
β1,10,1β: 10,
β1,10,2β: 10,
β2,10,2β: 11,
β3,10,2β: 12,
β4,10,2β: 13,
β4,10,3β: 13,
β4,9,3β: 14,
β4,8,3β: 15,
β4,7,3β: 16,
β4,6,3β: 17,
β4,5,3β: 18,
β4,4,3β: 19,
β4,3,3β: 20,
β4,2,3β: 21,
β4,2,0β: 21,
β3,2,0β: 22,
β2,2,0β: 23,
β1,2,0β: 24,
β1,2,1β: 24
}