if you check the replay of the validator that fails, you can see that:
https://www.codingame.com/replay/532224844
It should be enough for you to find the issue in your code.
if you check the replay of the validator that fails, you can see that:
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.
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.
wow my code is âoptimizedâ , sounds good lol
/// 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.
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.
Can you please avoid to share complete and working (or almost) code publicly. If really necessary, use the private messaging system. Thanks.
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."
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).