Power Of Thor - Episode 1 - Puzzle discussion


You could also make Thor walk like this: https://www.codingame.com/replay/385434856
This is my solution in C, was fun :slight_smile:


I am incredibly frustrated by this puzzle.

I declare CurrentTX and CurrentTY int variables before the while statement. I update those variables within each if statement. I have 8 if statements, one for each cardinal direction. I lose on the third challenge when Thor drops off the bottom of the map trying to go SW even though my code for going SW isn’t met because thor’s position is (18,17) and the Light’s position is (0,17) and thus CurrentTY - lightY IS NOT < 0.

else if (CurrentTX - lightX > 0 && CurrentTY - lightY < 0)

At that point he should start going east via this statement:

else if (CurrentTX - lightX > 0 && CurrentTY - lightY == 0)

But instead he keeps going SW. Again, just to be clear, I have variables for his current position and they are updated in the if statements.


It would be a lot less frustrating if you put debug statements in your program to understand what happens exactly. The stderr is made for this and to know the value of your variables and in which “if” statements the code flows would help you a lot.

Note: {∅, N, S} x {∅, E, W} = 9 possibilities. If you have 8 “if”, it won’t be enough in general.


Aries, yes I ended up solving the issue with debug statements. It ended up being an inversion of the updater code for the y position. For a puzzle that was supposed to teach conditionals, they really throw you for a loop with their decision to position 0,0 at the top left instead of bottom left.

8 Conditionals was absolutely enough though. One for each possible direction. I guess theoretically you could have one for “don’t move” but its not really necessary since none of the 8 conditionals will be met in that situation and so none of their code will fire. I mean, the provided solution in the puzzle only used 4 conditionals.


0,0 is top-left in most programming languages.


on the last case of test ur energy will not be enough to complete so u gotta do the move NE