Shadows of the Knight - Episode 1 - Puzzle discussion

why char bomb_dir[4]? it should be char bomb_dir[2] because you have 2 letters only or you can do this “if(bomb_dir[0] == “D” && bomb_dir[1] == “R”)”

Hello everyone, I am lost I try something in javascript but he doesn’t work, I need some help ! this is my code in javascript :

var x = W-1;
var y = H-1;
if ( bombDir === ‘U’){
y = Y0-1;
x = X0;

}else if(bombDir === 'R'){
    x = X0+1;
    y = Y0;

}else if(bombDir === 'D'){
    y = Y0+1;
    x = X0;
    
}else if(bombDir === 'L'){
    x = X0-1;
    y = Y0;
    
}else if(bombDir === 'UR'){
    x = X0+1;
    y = Y0-1;
    
}else if(bombDir === 'DR'){
    x = X0+1;
    y = Y0+1;
    
}else if(bombDir === 'DL'){
    x = X0-1;
    y = Y0+1;
    
}else if(bombDir === 'UL'){
    x = X0-1;
    y = Y0-1;
    
}
console.log( x , y );

}

Please read the external resources on the cover page. They will help you understand what is needed to solve this puzzle. Basically, you need to search more quickly than changing X and Y by 1 in each step, otherwise you’ll run out of rounds.

By the way, you may format your code properly in this forum by using the </> button on the formatting toolbar.

Do we agree that what’s in bomb_dir is a string ?

Yes, it can take on any of the 8 values as specified in the puzzle statement.

1 Like

Good morning ! Could someone help me understand how to implement binary search algorithm?

I tried to use if and else statements following the example of Gaurav Sen’s video but I can’t reproduce what he explains. I visualize the code that searches for the bomb.

I’ve got a bombs Y coord point changing, avoiding !
see that… Can please someone tell me what’s going on ??

The statement states that:

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.

Hello everyone, please tell me what I’m doing wrong:

import sys

import math

# Auto-generated code below aims at helping you parse

# the standard input according to the problem statement.

# w: width of the building.

# h: height of the building.

w, h = [int(i) for i in input().split()]

n = int(input())  # maximum number of turns before game over.

x0, y0 = [int(i) for i in input().split()]

lowerX, lowerY = 0,0

midX, midY = 0, 0

# game loop

while True:

    bomb_dir = input()  # the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)

    midX = lowerX + (w - lowerX)//2

    midY = lowerY + (h - lowerY)//2

    if bomb_dir == 'U':

        h = midY - 1

    if bomb_dir == 'D':

        lowerY = midY + 1

    if bomb_dir == 'L':

        w = midX - 1

    if bomb_dir == 'R':

        lowerX = midX + 1

    if bomb_dir == 'UR':

        h = midY - 1

        lowerX = midX + 1

    if bomb_dir == 'UL':

        h = midY - 1

        w = midX - 1  

    if bomb_dir == 'DR':

        lowerY = midY + 1

        lowerX = midX + 1

    if bomb_dir == 'DL':

        lowerY = midY + 1

        w = midX - 1

   

    print("midX...", file=sys.stderr, flush=True)

    # Write an action using print

    # To debug: print("Debug messages...", file=sys.stderr, flush=True)

    # the location of the next window Batman should jump to.

    print(midX, midY)

I tried to the first test case with your code, and the following is the console output:

Game information:

Locate the bombs, save the hostages! Batman is on window (2,3) The bombs are located below and to the right of Batman
0 3

Standard Error Stream:

midX…

Standard Output Stream:

2 4

Game information:

Batman moved from window (2,3) to window (2,4) The bombs are located below and to the right of Batman
1 3

Standard Error Stream:

midX…

Standard Output Stream:

3 6

Game information:

Batman moved from window (2,4) to window (3,6) The bombs are located below Batman
2 3

Standard Error Stream:

midX…

Standard Output Stream:

4 7

Game information:

Failure: invalid input. Expected ‘0 <= x < 4’ but found ‘x = 4’ Batman moved from window (2,4) to window (3,6) The bombs are located below Batman

The failure message tells you what you’re doing wrong. In the first test case, width is 4, so the valid values of x are 0, 1, 2 and 3. Your output of x is 4 and outside the range of valid values.

I had the same issue, Finally I’ve solved it by using:

fmt.Println(X0, Y0)

As the output.

I’ve an error #73. I can’t execute code for this puzzle.

Correcting Cutting is passing after I submitted, but it keeps failing in the Test Cases, This is Curious.
And any Hint to the Last Test Case “Not There” ?

In case you do not notice, you can check the replays of the validators. They can be found in MY REPORT > Details. You may get a better idea of what may have gone wrong by watching the replays. And you may share a link to a replay here.

There’s something wrong with the last test case; It won’t write to the error console. None of my code runs for that one for some reason. The others are fine.

That probably means your code contains a bug which does not handle that case properly. Maybe a condition which is never satisfied?

Well, I mean, in the main game loop, even if I try to console.error, with the input, it will not print anything. It’s only for this test case, like I said. I have no idea. There are no conditions in the game loop.

Actually, I think I know what it is now. I have a loop, which creates the board(the 2D array); And the board in this case is gigantic(9999x9999); So the loop takes longer to run, than the allowed time. Then it looks like nothing is being printed.

it’s the first middle puzzle i’ve been solved , and as a beginner, it’s really kindle my passion for python!

Some maths ?

With binary search, with n steps, i can find a number in a sorted list of at most 2**n -1 items.

In the tower test I have 6 tests available, and it seems to me that the tower is 80 tall but 2**6-1 = 63 < 80. so I can’t for sure find the result.

Where is my mistake?