Power Of Thor - Episode 1 - Puzzle discussion

Tu dois updater la position de Thor après chaque itération. Ca doit tjrs changer afin que tu puisses bien décider ou aller! :wink:

i wouldn’t have solved this in a million years on my own

For me there is a simple bug …
Thor position = (18,17). Light position = (0,17). Energy = 31
With this code :

        string directionX = string.Empty;
        string directionY = string.Empty;
                
        if (lightY > initialTY)
            directionY = "S";
            
        if (lightY < initialTY)
            directionY = "N";
            
        if (lightX > initialTX)
            directionX = "E";
            
        if (lightX < initialTX)
            directionX = "W";
            
        Console.WriteLine(directionY + directionX);

Will NEVER return SW… I tested the code in my VS, and it return W… not SW.
Any good explanation of the result ?

What if lightY==initialTY?

I don’t know what I am missing, but when I am doing the easy angle level, I can only use 15 energy and then it stop.
There are the last two output I got:

Console outputGame informationDebug (Errors Stream)Action (Output Stream) 
Game information:

Thor's moving...
Thor position = (18,17). Light position = (0,17). Energy = 31
14/15
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

Can someone help me to understand why is it doing that?
Thanks you

You run out of the map. Your y = 18, max is 17 here.

Right … The fact that Thor was moving during test blind me . :slight_smile: I update the solution and success the puzzle. :slight_smile: thx.

Can someone help me plz? :smiley:
I tried to make this puzzle in C but everytime I Thor runs off the map and dies in test 3/4.
I have no idea what I did wrong and I can’t show the full code so I will try to explain what I did.

The variables are TX, TY, LX, LY and the scanf is already put in place.
I start with
while (1)
{
Then I just put all the if rules to run in the 8 destinations.
I will just show the first one and then the rest are just like this one.

So if (TX < LX)
{
if (TY < LY)
{
printf(“SE\n”);
TX = TX++;
TY = TY++;
}

Then I go on with TY > LY and TY == LY and then comes the entire TX > LX and after the TX == LX

And it just ends with
}
}
}
return(0);
}

It seems that when Thor is on (18,17) and the light is on (0,17) Thor just runs of the map and dies.
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

Why does he does this? At (18,17) Thor has 18>0 and 17 = 17 so TX > LX and TY == LY so he should run W but he keeps going SW.

I also read throughout this thread that it has to do with updating Thors position but didn’t I do that with the TX = TX++ or TX = TX-- etc …?
And do you have to make a difference between Thors initial position and Thors current position so having variables
TX, TY, LX, LY, TIX (thor initial X), TIY (thor initial Y)?

I am confused =(

Before each printf, could you also print TX and TY on the standard error output? Doing so, if TX and TY does not have the value you would expect, you can try to see what’s going wrong.

In your case, you may be misupdating TX and TY in some if blocks, or I don’t know :slight_smile:

Use either TX = TX+1 or TX++, but not a mix of both.

Omg I feel so stupid now =(
Yes that totally worked hahahha
Thank u so much for the help :stuck_out_tongue:

Thats your destination.

It doesn’t test for the light in the upper area of the map.
I was running tests in a code I knew was wrong and got 100%.

I am trying to explain this code (I am a programmer) to my friend (not a programmer)

I am sorry but you are asking too much from people, it is like you make them jump from level 0 to level 8. If this is intended for people to learn how to program it is not fulfilling the purpose.

Could you be a little more complete please? What did not work out? And most important, was your friend interested in learning code?

I think this site works well as a complement with exercises to online classes / tutorial.

[EDIT: NO FULL CODE]

Why aren’t test 3 and 4 working? Thanks!

BeCAuSe yOu arE VIsUallY iMpaIREd! :eyeglasses:

1 Like

It is because Thor is a lemming and suicides at the end :frowning:

In the solution it lists pseudo code and I need some help interpreting it. Does ← represent an operator? If so, what operator? If not, what does ← and the right arrow represent? I’m thinking it’s not < or > or they would simply write those operators. Someone steer me in the right direction please.

The arrow is used for assignment

If you have :
j ← 41
j ← j + 1

Then after the first line, j contains the value 41. Then after the second line it contains it’s previous value (41) + 1, so 42.

1 Like