Power Of Thor - Episode 1 - Puzzle discussion

Im supid…
Its ok just I wrote thorX = thorX-- instead of just thorX-- or ++Thank for help.

This is just wrong (undefined behavior).
See this FAQ entry (it’s for C, but also valid for C++).

Ok, so i dont know why but whit thorX == thorX-- the game dont work
and just whith thorX--i’ve 100%…

I am having a bit of trouble with this, I think it might be the layout of the code I use, but in python I have this code
`light_x, light_y, initial_tx, initial_ty = [int(i) for i in raw_input().split()]
thorX = initial_tx
thorY = initial_ty

game loop

while 1:
remaining_turns = int(raw_input()) # The remaining amount of turns Thor can move. Do not remove this line.

# Write an action using print
# To debug: print >> sys.stderr, "Debug messages..."

# A single line providing the move to be made: N NE E SE S SW W or NW
if thorX > light_x:
    directionX = "W"
else:
    directionX = "E"
if thorY > light_y:
    directionY = "N"
else:
    directionY = "S"
if directionX == "W":
    thorX = thorX + 1
else:
    thorX = thorX - 1
if directionY == "N":
    thorY = thorY + 1
else:
    thorY = thorY -1
print directionY + directionX`

Can anyone help me with this? it just makes him go southeast for some reason.

Hello I have a problem and have no idea why it is not working when it should.
This is error message:

Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found ‘E’

Thanks for help. I am working in C.

Does this help? Suggestion: include unprintable characters in the error messages

Thanks man this could help I think I got it now.

Why cant i do this printf("%c%c\n",directionY,directionX); ?

it is the same output as printf("%c",directionY); printf("%c",directionX); printf("\n");rigth?

I need to someone update my code, because I don’t know how to write it and how to pass. I pass all three cases but can’t pass ‘optimal angle’…Pls help me. I code in PHP, this is my code:
$dir="" ;

if ($thorX > $lightX){
$thorX–;
echo ($dir=“W\n”);
;
}elseif
($thorX < $lightX){
$thorX++;
echo ($dir=“E\n”);
}

if ($thorY > $lightY){
    
    echo ($dir="N\n");
}elseif
($thorY < $lightY){
    
    echo ($dir="S\n");
    $thorY++;
}

Think about what your code outputs when Thor has to move (for example) NE, and what it should output.

I got it too. There’s what i wrote : printf("%s\n",strcat(directionY,directionX));
But i got a fault too don’t understand why

Hello, can somebody tell me how can I write switch in PHP?
I followed PHP manual.

switch($dir){
    case "S":
        $nowTY=++;
        break;
    case "N":
        $nowTY=--;
        break;
    case "E":
        $nowTX=++;
        break;
    case "W":
        $nowTX=--;
        break;
}

EDIT: ah my bad: NO “=” before ++

I have componed two way “if”

if ($nowTY==$LY)
    if ($nowTX<$LX)
            $dir = "E";
    else    $dir = "W";

For some reason my code is telling thor to go west when the initialTX > lightX. For some reason it goes to -1. Any ideas why?

my code for “power of thor” works for the first 3 level, but i do not know how change my code for it to work on the fourth level “optimal angle”.
here is my code…

[EDIT: NO FULL CODE]

Is this what an individual if statement should look like?
if (thorX >= lightX){
directionX= “W”;
–thorX;
}
I’m updating Thor’s position, but the standard output doesn’t change.

I’m a bit stuck on this puzzle. I’m fairly certain I’ve narrowed the problem down to my output what I have is:

if(thorY = lightY && thorX != lightX)
        {
            cout<< directionX<< endl;
        }else if(thorX = lightX && thorY != lightY)
        {
            cout<< directionY<< endl;
        }else
        {
            cout<< directionY<< directionX<< endl;
        }
(spaces added so code would display)
Now this code works for the first test but fails for all the rest. It causes Thor to walk straight in a single direction. Now I’m not looking for the solution, but what am I doing wrong? The way I read the code is: If Thor’s location matches the light location but the other variable doesn’t Thor should move towards the variable that doesn’t match. Else the loop should be ignored and the program should move to the next loop. What I’m finding the code is doing is ignoring the and statement so if thorX and lightX are the same he shouldn’t move along the X but he is. Am I wording the actions wrong?

Also I noticed if I switch between thorX = lightX to thorX == lightX the movement pattern is wholly different. Now I’ve been told to use “==” for equality checks and “=” for assignments. Why does “=” move thor one way and “==” another? Lastly, I noticed some people have used (directionY+directionX) for the output what is the difference from my variation directionY<< directionX?

If you use an assignment (one equal sign) in place of an expression, the assignment will be executed and the expression will always be true.

Here is what your code really does:

thorY = lightY;
if(true && thorX != lightX) {
  cout<< directionX<< endl;
} else {
  thorX = lightX;
  if(true && thorY != lightY) {
    cout<< directionY<< endl;
  } else {
    cout<< directionY<< directionX<< endl;
  }
}

Can you see that the line cout<< directionY<< endl;will never be executed?

Much appreciation that actually explains a lot.

1 Like

Now there’s just one more thing I don’t understand. Why is Thor automatically moving SE? The game starts Thor at (5, 4) Light (31, 4). I have two lines(one for x one for y) that state if thor == light that direction is assigned “”. I’m not updating the positions till after a direction is assigned. So shouldn’t the program assign directionY with a null character making Thor move East for the first turn? I should note at y = 8 the programs starts producing a single direction even though thor and light do not equal.