Power Of Thor - Episode 1 - Puzzle discussion

Hi,

I’m a newbie programmer. Now, I’m lost and need help to proceed forward. My code I’m able to write will be showed below:

[EDIT: NO FULL CODE]

Please give me a more detailed guideline for me to be able to proceed.

Much appreciated.

From a guy who is very passionate to learn coding :smile:

I don’t understand how your lines with thorX and thorY should work.

hello, I have a concern with the numbers 3 and 4. When Thor is on the line of lights (Y ), it continues to descend while I have this line in my code :

if (thorY == lightY){
        directionY = "";

I am in c ++
thanks for your help.

Do you update Thor’s coordinates?

Humm if thor > light thorX = thorX++ else thorX–
all time for X and Y.
I can post all code or not ?

I would say that if thorX > lightX, then incrementing thorX will increase the difference between thor and the light.

You should try to help thor in its quest to retrieve the light, not updating thor position to make you think he is going far away from the light.

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?