[Community Puzzle] A child's play

The case in your post shows there is no space for the robot to move upwards. No validators contain a similar situation, as the statement says

The robot initially moves upwards.

Also, there does not seem to be any validator where the robot has to completely retrace its original route in the opposite direction.

Actually validator 4 is the same as test 4 except for the number of operations.

By the way, in this forum, you can format the map using the monospaced characters button (</>) on the formatting toolbar.

My problem was that a -1 was in the wrong place, and the modulo range was [-1, n-1] insted of [0,n]

Yes, this is how it works (turning does not count as a move).
Though, that did not follow from the problem statement. Thus, I find the problem statement confusing.

1 Like

timeout after only 3 moves, LOL, I tried to optimize my code!

I accidentally deleted the code that handle the obstacles, I feel stupid!

Are their issues with the loop detection test cases?
I’ve verified the answer of one of them by hand. Should be 1 3. The test case says it should be different?
Do vectors not matter in the loop? If vectors matter then the answer should be 1 3. Can anyone confirm this?

If you find a test case to have an expected answer different from what you think it should be, please specify which test case it is, and list out all the coordinates of the path the robot takes. Then other people may compare them and answer you.

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
}

In the second case in your post, did you include ALL the coordinates as part of the cycle? Note that the initial upward path is NOT part of the cycle.

That’s a very good point. I’m going to have to verify it, but I think that’s it.

Edit: verified.
It was just a coincidence that being off by 1 was the correct / incorrect answer. What a coincidence… that threw me off the trail of what was really wrong.

The correct approach is to minus the previous steps associated with the starting node that completes the loop.
Because it’s the starting node that completes the node, it should’ve started at step 0. Anything above that means it came from previous unassociated travels and should be subtracted from the total steps to get the correct loop length.

Thank you for your help.

1 Like

I divided my solution to 2 phases.

  1. First phase is to find the length of looping path. Consider 2 cases, where the starting point is and is not on looping path.
  2. Second phase is to push the robot into the looping path and let it go a certain length of path.

My solution passed. However I think the validators are insufficient.

Denote L as the length of looping path, n as the legnth of path the robot move (the same as statement in puzzle) , m as the length of path the robot actually move (blue dashed line) and Kas the length of path from initial position of robot to the first gird in looping path (red dashed line).

What I do in second phase of my solution is simulating the move of robot for m steps. I let m = (n mod L)+2*L and passed. The item 2*L is for pushing the robot into looping path because n is large. This item is not right, and it just coincidentally succeed. It will fail if K > 2*L. Correct setting for m should be like m = (n mod L)+ceiling(K/L).

To sum up, new testcases/validators where K is much more than L is needed.

Anyone else having troubles with validator 9? I pass every tests and validators except for this one and there’s no way to know what’s wrong.

Validator 9 is the same as Test 9 except that [[n]] is different but still a small number. You can try different values of [[n]] and double-check the correctness of the answer of your code by manual calculation.

Thank you! I’ve been able to identify an oversight in my loop detection. Now everything passes, yay!

1 Like

A typo here

  • should be Next h lines...

    Next n lines: The map where the robot moves with . representing a free space, # an obstacle and O the starting position.

Missing tags

  • 2D array

  • Loops

  • Lists

  • Cycle Detection

Updated to [[h]]! I believe as a level 20 you should be able to update simple fixes like that yourself on the contribution - Just make sure to leave a note if you’ve updated it.

1 Like

Thanks. They can approve but cannot modify puzzles until they’re level 29.