Shadows of the Knight - Episode 1 - Puzzle discussion

if you check the replay of the validator that fails, you can see that:
image
https://www.codingame.com/replay/532224844

It should be enough for you to find the issue in your code.

The binary search uses two bounds for each axis to specify a search space, that’s 4 variables besides Batman’s coordinates given in inputs.

I am using C# here and I found one thing very wired for last test case Not there. For other language, Not there gets 14 jumps. But for C#, it only get 7 jumps?

I can not get pass the last test case in C#, but I can when using Python or C++

C# seems normal, there are 14 jumps in the last testcase.

The most probable explanation si that you give 2 outputs at every turn, so it halves your number of attempts. Check the way you do your output.

1 Like

I resolved but without using the number of step variable, I think I missed something.

Nope. The remaining jumps are “the limit to not cross”, but if your solution is optimized you don’t have to worry about it.

1 Like

wow my code is “optimized” , sounds good lol

1 Like
    /// inside the infinite loop
    if(bombDir.includes('L')) X-= Math.ceil(X / 2);
    if(bombDir.includes('R')) X+= Math.ceil((W - X) / 2);
    if(bombDir.includes('U')) Y-= Math.floor((Y) / 2);
    if(bombDir.includes('D')) Y+= Math.floor((H - Y) / 2); 
   // Where X and Y is the current position of Batman
   // and H and W is the dimensions of the building.

This worked for the first 2 test cases. But then Batman goes crazy on vertical scanning. I don’t know how the above solution is flawed. Thoughts?

W and H are the dimensions of the whole building, but after each jump the area with the bomb should get smaller. You need to take that into account.

You can enable the Debug view to see it.

1 Like

Shouldn’t it be W - 1 - X and H - 1 - Y ?
And why ceil for X and floor for Y ?
And yes you should update W and H.

I tried Updating the W and H and surprisingly it passed the 3rd test case. But the problem I see with this is the bomb may move.

Note: For some tests, the bombs’ location may change from one execution to the other : the goal is to help you find the best algorithm in all cases.

I used ceil in case the difference is an odd number.

anyways
 here’s the update on the two cases for 'L' and 'U'. still wrapping my head around the updating of W and H.

    if(bombDir.includes('L')) {
        W = X;
        X-= Math.ceil(X / 2);
    } 
    if(bombDir.includes('U')) {
        H = Y;
        Y-= Math.floor((Y) / 2);
    }

I think an easier way to understand what’s going on is to set the min, max of your search interval, let’s call them a and b for example.
First, a = 0 and b is the max value.
At each iteration, let’s call m the midle of a and b.
And then a becomes m or b becomes m, depending on the answer.

1 Like

Can you please avoid to share complete and working (or almost) code publicly. If really necessary, use the private messaging system. Thanks.

2 Likes

If you use Printf, need to add the trailing \n: fmt.Printf("%v %v\n", x, y)

I got this when i tried to run tests
“Attention : votre code n’a pas lu toutes les donnĂ©es disponibles depuis l’entrĂ©e standard avant d’avoir Ă©crit sur la sortie standard. Ceci cause une dĂ©synchronisation qui peut entraĂźner des comportements inattendus.”
what this means ?

It means "Warning: your code did not read all available input before printing an instruction, your outputs will not be synchronized with the game’s turns and unexpected behaviour may occur."

1 Like

I can’t see anything on the output panel. JS language. I can’t debug anything. Anyone experienced this?

what do you mean? I can see debug messages in your output

I mean that the left output panel doesn’t show any message. It stay black without any message: any console.error() or console.log() doesn’t show
.

I ran your code earlier and got console errors and outputs. Please share a screenshot of what you get (or better, a video capture if you can).