I don’t understand why validator won’t pass 1 and 4, yet the testcases all pass initially.
light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
current_x = initial_tx
current_y = initial_ty
# game loop
while True:
remaining_turns = int(
input()) # The remaining amount of turns Thor can move. Do not remove this line.
direction = ""
if current_y > light_y:
direction = direction + "N"
current_y = current_y - 1
if current_y < light_y:
direction = direction + "S"
current_y = current_y + 1
if current_x > light_x:
direction = direction + "W"
current_x = current_y - 1
if current_x < light_x:
direction = direction + "E"
current_x = current_y + 1
print(direction)
The explanations of the exercise do not say that we must calculate Thor’s new coordinates, but to write the direction he must take. I wasted a lot of time because of this
In the statement it does mention so, even though indirectly:
the variable initialTX: the starting X position of Thor.
the variable initialTY: the starting Y position of Thor.
Line 1: 4 integers lightX lightY initialTX initialTY. (lightX, lightY) indicates the position of the light. (initialTX, initialTY) indicates the initial position of Thor.
And one of the hints (which you can get by clicking the button to the left of the statement) state so more directly:
Thor’s coordinates are not updated by the referee program (they’re just sent to you during the first turn). Therefore, you must update them each time you issue a move command in stdout, so on every turn.
The word “starting” does not in any way indicate that Thor’s position should be recalculated.
The fact that Thor moves in tests 1 and 2 is misleading about the fact that the coordinates had to be recalculated.
I didn’t look at the hints to solve problems. The indication should have been written in the main rules.
The point is, if only Thor’s starting position is given, and if you need to work out how Thor should move subsequently, you either
calculate each move based on Thor’s subsequent positions, and since they are not given, it implies that you have to keep track of and recalculate them yourself,
or
calculate all the moves based on Thor’s starting position (in fact, you can work out all the required moves in the first turn).
I mean, recalculating Thor’s subsequent positions is not a must in this puzzle, so why should the main rules state so?
Beware, some other games on this platform also don’t provide you with the information on the latest game state (e.g. Ultimate Tic Tac Toe). If you always rely on the puzzle statement to tell you explicitly to update the variables, you won’t be able to pass them.
Hi. Can you please help. I did 1 test, but I can’t solve 2. the torus just teleports to the end of the map, and when I try to update its coordinates, the first test is no longer performed, what should I do?
So far I’ve tested different lines of codes, and all of them output the exact answer.
My problem is optimization : what should I do to make my code run faster?
The number of variables is not necessarily an indicator of speed. Perhaps there are some other issues with your code? If you see a timeout error, it may mean e.g. your code has an error, or your code has an infinite loop and cannot reach the output code, or your code outputs something after reading the next inputs, which is too late.
why this code doesn’t work for 03 and o4 test cases. Any hint where it is wrong
var thorX= initialTx
var thorY = initialTy
// game loop
while (true) {
val remainingTurns = input.nextInt() // The remaining amount of turns Thor can move. Do not remove this line.
var dirX = ""//x --> W , E t>l = 'w' else e
var dirY = ""// y-> N,S //ty>ly dir =n, else dir= s
if (thorX > lightX) {
dirX = "W"
thorX = thorX - 1
} else if (thorX < lightX) {
dirX = "E"
thorX = thorX + 1
}
if (thorY > lightY) {
dirY = "N"
thorY = thorY - 1
} else if (thorY < lightY) {
dirY = "S"
thorY = thorY + 1
}
// A single line providing the move to be made: N NE E SE S SW W or NW
println(dirX+dirY)
}
There is definitely a bug and this is the explanation: I passed all the tests except the easiest one 'Straight Line"
When you head East “print(‘E’)” then you need to increment initial_tx+=1 by one . But the program does not accept it. The test case pass only if you do the inverse: initial_tx-=1 which means heading West and this is False.
Please can the admin review the test cases , there is defnitiley a bug