Power Of Thor - Episode 1 - Puzzle discussion

Hey everyone! I’m starting a code club at my campus and last week I introduced five students to The Power of Thor, Episode 1. After about an hour of trying at it some had gotten pretty close. I filmed this solution, and plan to keep making videos to help get more beginners learning on this platform. Please share it with anyone you know that’s trying to learn to code, and if you had any difficulty with this puzzle this should help you get through it. Feedback welcome! :slight_smile:

What is the difference between
cout >> Y >> X
and
cout >> X >> Y
???

You read the first value as X then the second as Y (cout X Y) … or Y then X (cout Y X).

This game has a bug up & down not working

Probably your code contains the bug which causes up and down not to work. You may PM your code to me to have a look.

The puzzle is about about conditionals and I have to move Thor using console.log()…what is going on.??

Basically the games on Codingame tell you where the character is and where he needs to go. You then have to print out a move in the format the game wants. If you read through the sample code, it tells you what it wants but then prints a wrong move. You have to use logic taking in the inputs every loop to print out where to go.

Thor wants moves in “L” for left, “R” for right, “U” for up, and “D” for down. It allows you to move diagonally in one move by using, for ex: “RD” for right and down. You would build your move string with an if/then conditional to calculate how to move and build your move string accordingly.

if(thor.x < target.x && thor.y < target.y ) { move = “RD”; }
else if (thor.x < target.x && thor.y == target.y ) { move = “R”; }
else if (thor.x < target.x && thor.y > target.y ) { move = “RU”; }
//…and so on

then send it to the console:

console.log(move);

I’ve only worked on the first part, but it was very cool and enjoyable to work on this! I think this is part art, part programmatic poetry and just fun, thank you!

Hello, could you help me please, i did this code :slight_smile:
class Player {

public static void main(String args[]) {

    Scanner in = new Scanner(System.in);

    int lightX = in.nextInt(); // the X position of the light of power

    int lightY = in.nextInt(); // the Y position of the light of power

    int initialTx = in.nextInt(); // Thor's starting X position

    int initialTy = in.nextInt(); // Thor's starting Y position

    int thorPositionX = initialTx;

    int thorPoistionY = initialTy;

    String directionX = "", directionY = "";

    // game loop

    while (true) {

        int remainingTurns = in.nextInt(); // The remaining amount of turns Thor can move. Do not remove this line.

        // Write an action using System.out.println()

        // To debug: System.err.println("Debug messages...");

        if (thorPoistionY < lightY) {

            directionY += "S";

            thorPoistionY += 1;

        } else if (thorPoistionY > lightY) {

            directionY += "N";

            thorPoistionY -= 1;

        }

        if (thorPositionX < lightX) {

            directionX += "E";

            thorPositionX += 1;

        } else if (thorPositionX > lightX) {

            directionX += "W";

            thorPositionX -= 1;  

        }

You have to print your answer in each round. Please read the comments in your code if you do not know how to do it.

By the way, you can format your code properly by using the </> button in the formatting toolbar.

I’m using Javascript. In test case 3 (Easy Angle), Thor moves SW, as he’s supposed to, but he walks outside the barrier and misses his target. Any tips or hints on how to adjust the angle?

You don’t have to output SW for all the turns. You may print W instead when Thor is “south enough”.

1 Like

// lightX: 31,4 87 87 88

// lightY: 31,4 87 87 88

// initialTx: 17,16 18,17 19,18

// initialTy: 31,4

var lightX, lightY, initialTx, initialTy int

fmt.Scan(&lightX, &lightY, &initialTx, &initialTy)



for {

    // remainingTurns: The remaining amount of turns Thor can move. Do not remove this line.

    var remainingTurns int

    fmt.Scan(&remainingTurns)

           

    // fmt.Fprintln(os.Stderr, "initialtx initialty...")

   

    // A single line providing the move to be made: N NE E SE S SW W or NW

    fmt.Println("SE")                

    this is my code im on language go it looks correct and it gets Thor to move se but not to the power source ;(
                                                           can someone help?

You print “SE” and Thor moves SE quite correctly. If you want Thor to move in some other directions, you have to add some code of your own.

Also, your code may be formatted properly if you use the </> button in the formatting toolbar. Your question should be outside the code, unformatted.

hi!
so i fond out that whatever direction that i put in the println Thor would go but whenever i try putting
multiple directions he wouldn’t move
at all .
can you help?

Have you read the hints to the left of the puzzle statement? Those should help you. You are supposed to output one direction per turn, the direction dependent on what the current location of Thor is in that turn.

hi!!
ok, so I figured out the top two, but I still cant figure out the easy angle and optimal angle.

Note that you aren’t restricted to a single direction for all the turns. For example, you may first instruct Thor to go NW/NE/SE/SW, and once Thor is good enough in one of the directions, you may then instruct Thor to go N/W/S/E for the rest of his journey.

Why my code is failling though its correct

var inputs = readline().split(’ ');

const lightX = parseInt(inputs[0]); // the X position of the light of power

const lightY = parseInt(inputs[1]); // the Y position of the light of power

const initialTx = parseInt(inputs[2]); // Thor’s starting X position

const initialTy = parseInt(inputs[3]); // Thor’s starting Y position

var ThorX = linitialTX

var ThorY = initialTY

// game loop

while (true) {

const remainingTurns = parseInt(readline()); // The remaining amount of turns Thor can move. Do not remove this line.

var directionX = "";

var directionY = "";

if (ThorX > lightX) {

    directionX = "W";

    thorX--;

} else (ThorX < LightX) {

    directionX = "E";

    thorX++;

}



if (ThorY > LightY) {

    direction = "N";

    thorY--;

} else (ThorY < LightY) {

    direction = "S";

    thorY++;

}

Print (directionY + directionX)

}

Because it is incorrect. Check all the variable names again - there are some typos.

By the way, you may format your code properly by using the </> button on the formatting toolbar.