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âŚ
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.