Shadows of the Knight - Episode 1 - Puzzle discussion

Thank you so much for this challenge. I spent a whole day on it to figure it out from scratch and without any help or cheating. It was a great experience, I learned a lot from it.

1 Like

Iā€™m pretty new to coding, so this one was pretty difficult for me, until I started putting comments on my code to keep track of what it was actually doing, until I started putting comments on my code to keep track of what I was actually doing. Turned out I was trying to send moves without adding them to my position. Whoops. Finally got everything to work except the evasive test, learned how to force all my moves to round up, and got that sweet, sweet 100%

Hi, Iā€™m trying to solve this puzzle using Python 3.
Is it normal that when Batman is on the same ligne as the bomb, my code returns True when checking if ā€˜Dā€™ and ā€˜Rā€™ are in the variable bomb_dir ? Shouldnā€™t bomb_dir only contain ā€˜Rā€™ ?
I cannot upload images, so hereā€™s my code:

while True:
bomb_dir = input()
x = 0
y = 7
print(x, y)
print(x, y)
if ā€˜Dā€™ in bomb_dir and ā€˜Rā€™ in bomb_dir:
print(True)

And hereā€™s the error message I got:

Failure: invalid input. Expected ā€˜x yā€™ but found ā€˜Trueā€™
Batman moved from window (0,7) to window (0,7)
The bombs are located to the right of Batman

Thank you in advance for your time and answers

yes, itā€™s normal. You can see DR (down-right) is in the list of possible directions
image

gotta say that was hard to me, but the solution is justā€¦ nahā€¦

I need help i do not know what iā€™m doing

2 Likes

for javascript

Yeah, indeed Javaā€™s crypt is a hard level in this game.

1 Like

Is there really a generic solution, that solves the test case 4 Tower in a generic way for all possible bomb positions? There are 79 possible positions and 79 > 2^6 so there will always be cases where one needs 7 hops or am I getting something wrong?

thanks in advance and best regards

1 Like

Of course thereā€™s a solution ! :wink:
My code solve this test and the corresponding validator in 5 jumps.
I donā€™t get your ā€œ79 > 2^6ā€ā€¦

I can also code a solution that works for that test case and maybe also for the other test cases, but generally speaking Tower comes down to finding a random number from 1 to 79 by only asking yes/no questions, in this case ā€œis the bomb (below | above) meā€. That comes don to finding a binary representation of the sought number. With 6 bits you can only represent 64 (2^6) numbers, so I doubt that there is a generic solution that solves every possible test case. But maybe I am missing something.

1 Like

I meant ā€œOf course thereā€™s a generic solution !ā€ and ā€œMy generic code solve this test and the corresponding validator in 5 jumps.ā€
Finding generic solutions and donā€™t hardcode the tests is one of principles of the platform.
I think that your binary representation approach is misleading you. Have you toke a look to the resources on the puzzle page ?

Hello. Sorry Iā€™m new here. Is there a way to know the location of the bomb or how itā€™s represented in the problem (like does it have a value)? Thanks.

The bomb is represented by two coordinates (x, y) but these coordinates are hidden, theyā€™re never given to you.
The only information you have are these U, R, D, L indications.
The only moment you know the coordinates of the bomb is when you finally output them and the game referee tells you that you find the bomb.

As for what strategy you should use to find the bomb fast enough, just think about it like a 2D version of the ā€œguess the numberā€ game where you must guess a number and youā€™re told if itā€™s bigger or smaller.
Say you must guess a number between 1 and 100, a good strategy would be to try 50 first, so that you can halve your space search. And then at every turn you try to halve your space search like this.

1 Like

Hello, is there is something faster than binary search for this problem ? it seem i miss one extra turn to fully complete the tower test

Binary search is the way. Try doing this by hand and see if your algorithm gets the same results

1 Like

yea i am not understaning how they want me to code this.

Hi,
I used the binary search. It passed the first test case but not sure why it didnā€™t pass the other test cases. Please help.

while True:
    bomb_dir = input()  # the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
    if bomb_dir == 'U':
        y0 = (h+(y0-1))//2
        x0 = (x0 + w) // 2 
    elif bomb_dir == 'UR':
        y0 = (h+(y0-1))//2 
        x0 = (w+(x0+1))//2
    elif bomb_dir == 'R':
        x0 = (w+(x0+1))//2
        y0 = (h+y0)//2 
    elif bomb_dir == 'DR':
        y0 = (h+(y0+1))//2
        x0 = (w+(x0+1))//2
    elif bomb_dir == 'D':
        y0 = (h+(y0+1))//2
        x0 = (x0 + w) // 2 
    elif bomb_dir == 'DL':
        y0 = (h+(y0+1))//2
        x0 = (w+(x0-1))/2
    elif bomb_dir == 'L':
        x0 = (w+(x0-1))//2
        y0 = (h+y0)//2 
    elif bomb_dir == 'UL':
        y0 = (h+(y0-1))//2
        x0 = (w+(x0-1))//2
    
    print("{0} {1}".format(x0, y0))

Hi,
I need a little help!
All my tests are passing in the IDE but ā€œLess Jumpsā€ wonā€™t pass on submitā€¦

Whatā€™s the problem?

Thankā€™s in advance!