Power Of Thor - Episode 1 - Puzzle discussion

If thorY > lightY, the direction should be “S” right? But it’s not working!

One more time for the world: do you update Thor’s coordinates? :grinning:

susprised just a few people thought about the spaceship operator here (?)

Hello everyone!

Is there a way to print Thor’s current position?
I’m using JS and if I use console.log it gets out of the program, for it interprets as a movement command.

Thanks m8s!
TP

did you check the comments in the code?
image

Thanks Thibaud!
with console.error I managed to see that the variable I created to monitor Thor’s current position is working. I also discovered that I’m most likely not using it right, for Thor keeps wondering off the grid.

Will work on that.
=]

Found my error!
I forgot to clear my directions string from previous values!

1 Like

Hello, in the diagonal ones I tried to change direction but Thor never follows the second instruction, I do the first if to the west then at certain point I do the South but it never stops. Or if I go directly to the point with SW it does go right to the light and fails.

Did you have a look at the hints offered in the IDE?

Why doesn’t the instructions have clear descriptors of the properties of the sprites to be controlled. Nothing in the instructions state that the Thor or light have declared properties named ThorX, ThorY for use. Assuming this is the wrong way to teach programming. A developer would be able to see by the code base that the originating sprite should have publicly exposed properties. If your trying to teach the use of standard in and out on a class/object for the purpose of reverse engineering then please make that clearer in the lesson.

First, the “sprite” has no “properties”. The viewer is just here to help visualization, and most of the puzzle does not have one. ThorX and ThorY are just arbitrarily chosen variable names, you are free to rename them LokiX and LokiY if you want to.
Secondly, the content of the inputs is clearly described in the statement, and the base code is just here to help you to parse it. But you are not forced to use it either.
Finally, the CodinGame purpose is not to teach programming, but to provide a support to practice, and eventually to competition. This is a puzzle, not a lesson like you say, its purpose is to be fun and to help beginner practicing basics notions like loops and conditional statements, not to teach anything.

Hey everyone!

I’m having troubles fixing this easy puzzle =/ it passed the first two tests but not the others. I saw already the solution but I still don’t understand what’s wrong with my code!
Cause someone please give me some help? thanks a lot in advance!!

var inputs = readline().split(' ');
const lightX = parseInt(inputs[0]); // the X position of the light of power
const lightY = parseInt(inputs[1]); // the Y position of the light of power
const initialTX = parseInt(inputs[2]); // Thor's starting X position
const initialTY = parseInt(inputs[3]); // Thor's starting Y position
let x = initialTX;
let y = initialTY;

while (x!==lightX || y!==lightY) {

const remainingTurns = parseInt(readline()); // The remaining amount of turns Thor can move. Do not remove this line.
let dirx = '';
let diry = '';

if (x > lightX) {
    dirx = 'W';
    x--;
} else if (x < lightX) {
    dirx = 'E';
    x++;
}

if (y > lightY) {
    diry = 'N';
    y--;
} else if (y < lightY) {
    diry = 'S';
    y++;
}

console.log(dirx + diry);
}

Would you rather say East-North or North-East ? :slight_smile:

2 Likes

:dizzy_face: Of course!! :sweat_smile:Thank you very much, @Djoums !!

Standard Output Stream:

SW

Game information:

Thor’s moving… Thor position = (18,17). Light position = (0,17). Energy = 31
1314

Standard Output Stream:

SW

Game information:

Failure: Thor wandered off the path and died (invalid position). Thor position = (17,18). Light position = (0,17). Energy = 31

CODE
if((initial_tx<light_x)and(initial_ty<light_y)):
print(“NE”)
elif((initial_tx<light_x)and(initial_ty>light_y)):
print(“SE”)
elif((initial_tx>light_x)and(initial_ty<light_y)):
print(“SW”)
elif((initial_tx>light_x)and(initial_ty>light_y)):
print(“NW”)
elif((initial_tx==light_x)and(initial_ty>light_y)):
print(“N”)
elif((initial_tx==light_x)and(initial_ty<light_y)):
print(“S”)
elif((initial_tx>light_x)and(initial_ty==light_y)):
print(“W”)
elif((initial_tx<light_x)and(initial_ty==light_y)):
print(“E”)

Hey !
Welcome on our forum! Though on internet and speaking of code, the ones susceptible to answer you are humans. So publishing your logs and your code like you did is not the better way to ask them for help. I cordialy invite you to retry, with some human sentences, some politeness, and explanations about your problem.
Have a nice day !

1 Like

Same problem exist. I write code and again error occurred. After that, i check solution, the code is same but again error occurred.

It took me much longer than it should have to release I needed to update Thor’s position each loop…

I guess I got there in the end…

I tried abit Bash but no matter what I do I always get an “command not found” exception.
Is there a problem with bash?

Nope. Just solved it in Bash and it worked with no problems.
Make sure your code syntax is correct :slight_smile:

1 Like