Power Of Thor - Episode 1 - Puzzle discussion

got it thanks

Hello,

So i complete the code in Java by using the comparaison between lightY/lightX and thorY/thorX position to determine the direction (N, S, E, W) and it’s working just fine with the update of thorY and thorX.

I wanted to try a different approach by using the difference between lightY and thorY and compare it to 0:

int diffY= lightY-thorY;
int diffX = lightX-thorX;

diffY>0 → direction += “S”;
diffY <0 → direction +="N;
diffX >0 → direction += “E”;
diffX <0 → direction += “W”;

I update the thor position
but it’s not working for the 3rd and 4th tests. thor doesn’t stop and died.

I try to add else (diffY =0) { direction =“”;} but il doesn’t change the problem

Can someone tries to explain to me why this method doen’t work ?

Thank you for your help !

What does your code output for those tests?

Hello, in case you are coding in C: don’t forget to write \n at the end of your answers or you won’t pass the tests
.
Examples:
printf(“NW\n”);
printf(“W\n”);
etc

hello, I wrote this code in c language and I don’t know what’s wrong with it :
for(;:wink: {
if (light_x > initial_tx) {
printf(“E”);
initial_tx ++;
}
}

What about West, South and North?

new in this community. can someone tell me how to execute my code in the game and if it is self executed then why does my code still not work although i took reference from the hints???

Your code is executed when you click PLAY TESTCASE or PLAY ALL TESTCASES (before you finally submit your code). You should be able to see the result of the execution in the console.

Fixed now probably!

Continuing the discussion from Power Of Thor - Episode 1 - Puzzle discussion:

Can anybody tell me what’s wrong with my code ? I have written it in java .
while (true) {
int remainingTurns = in.nextInt(); // The remaining amount of turns Thor can move. Do not remove this line.
String directionY = “”;
String directionX = “”;
// Write an action using System.out.println()
if(initialTx>lightX){
directionX = “W”;
++initialTx;
}
else if(initialTx<lightX){
directionX = “E”;
–initialTx;
}
if(initialTy>lightY){
directionY = “N”;
++initialTy ;
}
else if(initialTy<lightY){
directionY =“S”;
–initialTy ;
}
// To debug: System.err.println(“Debug messages…”);

        // A single line providing the move to be made: N NE E SE S SW W or NW
        System.out.println(directionY+directionX);
    }

Condition is still passing after coordinate increases

You should change ++ to -- and -- to ++. Take the first branch as an example, if initial Thor’s position is greater than light position, Thor will reduce (not increase) his x-coordinate after moving west and reduce the distance gap.