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.

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

Thanks for reading…

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.

I genuinely feel too dumb right now. Cannot get the second challenge of getting Thor to do down. Any pointers? Trying to learn python

If you look to the left of the puzzle statement on https://www.codingame.com/ide/puzzle/power-of-thor-episode-1, you’ll find a HINTS button. Those hints may help you get started.

You’ll also find some Python learning resources here.