[Community Puzzle] A child's play


#1

https://www.codingame.com/training/medium/a-childs-play

Send your feedback or ask for help here!

Created by @Magicien-d-oz,validated by @bbb000bbbyyy,@dbdr and @JBM.
If you have any issues, feel free to ping them.


#2

the code of my progress has disapeared, what happened?


#3

it most likely happened because the contribution has been updated. This is a bug on our side. I’ll check with the devs where we are on the resolution. Meanwhile, you can access your submit history by clicking on “results” on the left menu and then the “history” tab.


#4

Hello everyone,

Anyone had a problem with validator test 5 ?
I pass everything else (tests + validators).
Or maybe can i have what is tested specifically in this test more than in others ?
(i’m pretty sure it’s not because of the time taken because i use the trick with a “path” built until we reach the start position).

Thx


#5

Hi Pox,

I had the same issue and it took me a while to figure out that you may not always reach the start position. This assumption was at least the problem for me to fail at Validator 5 while passing all other tests…

Best regards
Masshood


#6

I will look at it more closely.
Thank you


#7

I would suggest a test 6, where the map path is a P and the robot make a loop but does not go back to initial position, such as:
##########
#. . . . . . . . #
#. ######. #
#. ######. #
#. . . . . . . . #
#. ########
#o########
##########


#8

Plot twist: I tried adding it, but even the author’s code won’t get it right.

This puzzle has already been “solved” by 331 persons now, it’s a bit late to invalidate all of their solutions.

I’ve updated the puzzle statement to subtly hint the robot is already on the loop path; you’re welcome to submit a harder version of it if you’re so inclined. (by harder I mean: not initially being on the path won’t be enough, add another twist please).


#9

Can someone tell me if I am on the right track, test 1 is looking for (7 1) but my robot never ends up there. It keeps following this loop

...#........
...........#
............
............
..#↑........
..........#.
Turning E
Turn: 986 (3, 1)
...#........
...→.......#
............
............
..#.........
..........#.
Turning S
Turn: 985 (10, 1)
...#........
..........↓#
............
............
..#.........
..........#.
Turning W
Turn: 984 (10, 4)
...#........
...........#
............
............
..#.......←.
..........#.
Turning N
Turn: 983 (3, 4)
...#........
...........#
............
............
..#↑........
..........#.
Turning E
Turn: 982 (3, 1)
...#........
...→.......#
............
............
..#.........
..........#.

Fixed it - i thought the robot continued forward until it hit a wall but it only moves 1 square at a time.


#10

Now I am failing all tests from 3 onwards due to timeouts. I am using SplFixedArrays to speed things up but still no luck. Is this challenge possible in php?


#11

In one word : yes
I solved it in php and without SplFixedArrays.
Tips : try to look the robots movements …


#12

Hello,

Masshood was right, for the 5th validator, it seems you never reach the initial position (it can be seen like the example of docbohanh).
The fact is with my algorithm, i stop stepping only if i reach the initial position.

So instead i can give this advice which worked for me : i add another variable that compute the maximum that can be for the path taken.
e.g : if you have a 5w 6h array and 10 obstacles, you have 5*6 - 10 (= 20) steps maximum until reaching a loop (it can be optimized but that’s not the goal).
So if you reach this maximum, it means you will never reach your initial position, so you can set the new initial position where you stand because it is in the loop.

If you take the example of docbohanh, it means you can compute the max : 10w, 8h, 58 obstacles = 10*8 - 58 = 22.
So after 22 iterations, you are assure to be in a loop where you will be again, so you can set the new initial position and continue your algorithm as usual.

Not sure if i’m clear, so don’t restrain to ask questions.

see ya