# 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(; {
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.

It has a bug when you are using python. The tests pass ok but the third check do not passâŚ

I used Python and all tests and validators are OK.

does anyone know how to reduce the amount of string used to move Thor?

i.e.

While true
initial_tx != light_x
destinationX = light_x

initial_ty != light_y
destinationY = light_y

is this possible? i get a syntax error when trying to automate his movements.

Could you please explain a bit more about what youâre trying to do, like, how you intend to move Thor? Iâm afraid I canât understand your message.

If you want to reduce the number of turns to move Thor, you should move Thor in a diagonal direction as many times as needed. For example, if you move Thor N and then E, thatâll take two turns, while it takes just one turn to move Thor NE directly.

itâs more, iâm looking to make the code smaller? like, after i figured out the X Y axis idea, to go N +/- 1 depending on initial_ty. I wanted to see if i can condense the script for the code? is there any way instead of doing +/- = 1 on the X/Y axis, without having to utilize numbers? or is the most efficient way of reaching the destination just +/- 1?

Once youâve got the initial data, you can already plan ahead what moves to do without referring to subsequent data. Maybe thatâll help you condense the script in some way? But even then, you still have to âutilize numbersâ for at least one turn.

right. i feel like doing if thor_x > light_x:
direction_x = âWâ
thor_x -= 1

isnât good enough in a sense? to have one string per direction feels like it needs to be made more efficient so iâm trying to figure out how i can create a string that makes Thor move without as much lines of code.