Power Of Thor - Episode 1 - Puzzle discussion

Read carefully which tests did not pass.

I write with this code:
else if (LY>TY && TY<18)
                    {
                        Console.WriteLine(“SW”);
                    }
but Thor still go in (x, 18) spot. :frowning:
btw, I do it with C#

As said several times in this topic, you have to update TX and TY by yourself :wink:

Been a while. This have became an optimization challenge since then. Btw, the whole point of my post had been not to give an implementation. But since you have insisted, here you go in py3:


directions = { complex( 0, 1):'S' ,
               complex( 1, 1):'SE',
               complex( 1, 0):'E' ,
               complex( 1,-1):'NE',
               complex( 0,-1):'N' ,
               complex(-1,-1):'NW',
               complex(-1, 0):'W' ,
               complex(-1,1): 'SW'
             }

L=complex(LX,LY)-complex(TX,TY)

d = min(directions,
    key=lambda d: math.acos( (d*L.conjugate()).real / abs(d) / abs(L) ))

Edit: No Full Code Allowed :slight_smile:

In Python2:

>>> 1j*1j
(-1+0j)

I was having a similar issue… after not getting it to work around the edges properly I reframed my objective…

1: determine an “offset” when the game starts which is the X,Y distance between Thor and the Light
2. move to reduce the larger magnitude of the offset (E, W, N, S)
3. until Thor is diagonal from Light, then move diagonally to reduce offset

I got 100% on this game! So no bug in the game but only in your head :smiley: :stuck_out_tongue: [no pun intended]

Your code is single lived PROCESS on their server. You see - Thor’s potitions are assigned BEFORE the Game loop? Of course you MUST keep track on his position by yourself :stuck_out_tongue: (100% here)

Hi, Im using Javascript for this game, but i dont know how to update the position of Thor and i need that info to make the optimal angle thing

I am having some trouble here, i don’t know if its something i am doing wrong.
Its in the third test,

while (true){
if(LY==TY && LX < TX)
                        System.out.println(“W”);
else if(LX < TX && LY > TY)
                        System.out.println(“SW”);
}

according to the code, Thor must move towards WEST when LY==TY.
but he keeps moving towards SW and wander off…

1/15
Thor’s ready to go.
Thor position = (31,4). Light position = (0,17). Energy = 44
SW

2/15
Thor’s moving…
Thor position = (30,5). Light position = (0,17). Energy = 43
SW

3/15
Thor’s moving…
Thor position = (29,6). Light position = (0,17). Energy = 42
SW
.
.
.
13/15
Thor’s moving…
Thor position = (19,16). Light position = (0,17). Energy = 32
SW

14/15
Thor’s moving…
Thor position = (18,17). Light position = (0,17). Energy = 31
SW

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

at 14/15, condition LY>TY fails and the code in it was not suppose to work…
LY==TY is true at that point, but that doesn’t run, what is wrong here??

Basically for the same reason that, if you write “room temperature” on a shoes box, it won’t magically become a thermometer. It will stay a dumb box with “room temperature” written on it. Same for TX which is not the Thor’s position along the abscisses (see this if it is not clear).

How do you play this game?

Hello, i have a problem. When i set the TY to be less than 18, when it reaches 18 it doesn’t stops. The code that i’m writing is:

while (TX != LX || TY != LY) {
            if (TX != 0 && TX != 40) {
                if (TX > LX) {

System.out.println(“W”);
                }
                if (TX < LX) {
                    System.out.println(“E”);
                }
            }
            if (TY != 0 && TY != 18) {

if (TY > LY) {
                    System.out.println(“N”);
                }
                if (TY < LY) {
                    System.out.println(“S”);
                }
            }
        }

When i tested in eclipse everything look fine.
P.P. In eclipse any condition for direction i replaced with TX++ or TY–
N = TY-1
S = TY+1
W = TX-1
E = TX+1

The first and the second condition work correctly

That definitely is a running gag.

1 Like

What do you mean?

Because you are just asking the very same question that the guy above you who did the same thing with the guy above him and so on up to the start of this thread. Of course, the answer has almost been given as often. Beside this ineffective Snapchat way of looking at a forum, I’m really wondering why so many stumble on this point. Do they mistake TX and TY for some kind of function returning the current Thor’s position? Or assume that their program is running in a more complex multithreaded framework where TX and TY could be modified outside their code?

1 Like

I’m sorry, i see the above question, after i post my. After using the log output for errors, I saw that each iteration TX cannot changes. Then I create new variables and their values assigned for the X and Y Thor

Thank you so much, I updated Thor coordinates and got 100%

1 Like

I got it now… with 100%… Thanks… The problem was that, the Console Output shows the position of thor at each point. I thought its updating automatically. I read through the comments above and was wondering how and where to update these coordinates if its already changing…

Hello,

The coordinates don’t get updated in the loop, so what I did was this, I declared two more variables(outside the loop) each equaling the difference of the X and Y coordinates (x = LX - TX) and after few if conditions.
if (x>0) and inside this if 3 more (if/else if/else) first was if y was > than 0 then y was < than 0 and if neither y was = to 0 and in each condition increase or decrease y and x (update the data manually).
ex: "if (x>0)
{
if(y>0)
{
cout<<…<<
x = x - 1;
y = y - 1;
}
else if

}