Power Of Thor - Episode 1 - Puzzle discussion

Do you update Thor’s position?

Hi i cannot reach third and fourth light due Thor lose all energy before he touche the light. Even i try specjal test case for that 2 cases but still he stops like 4 pixel before touch light.
(Using C++)
BR
Grzegorz

Do not mean to be rude there is a little error in the description

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

I suppose it is meant to say

W or NW

Really enjoying this puzzle

Hello, I find this platform really useful.
What I learned from this exercise was:
-Be aware where the 0,0 origin is located, so you move in the right direction, I made the mistake to assume origin was in lower left corner when is actually in upper left.
-You would need to calculate the direction, based on a copy of the original position, and update the new Thor’s location inside the loop, I made the mistake to calculate based on initial location of Thor, so my direction was always the same.

Thor lose all energy before he touche the light.

You have to move him diagonally until he on the same X or Y as the light. (for example, if Thor is 0,0 and light is 6,3 you have to output SE, SE, SE, E, E, E)

all of this is written in the rules though

I don’t know why i use this code but it didn’t work from cases 3.
I tried to used the solution one but it didn’t even work in case 1.
Can anybody help me?
import java.util.;
import java.io.
;
import java.math.*;

class Player {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String NS = "";
        String WE = "";
        int XL = in.nextInt(); // the X position of the light of power
        int YL = in.nextInt(); // the Y position of the light of power
        int X = in.nextInt(); // Thor's starting X position
        int Y = in.nextInt(); // Thor's starting Y position

        // game loop
        while (true) {
            int remainingTurns = in.nextInt();
            //NS direction
            if(Y > YL){
                NS = "N";
            }
            else if(Y < YL){
                NS = "S";
            }
            else{
                NS = "";
            }
            //WE direction
            if(X > XL){
                WE= "W";
            }
            else if(X < XL){
                WE= "E";
            }
            else{
                WE= "";
            }
            System.out.println(NS + WE);
        }
    }
}

This have been discussed here multiple times. You have to update Thor’s coordinates. Otherwise he will choose the same direction every turn.

1 Like

I have passed every test condition except the angles… Everything goes well until Thor ultimately hits a wall, but he shouldn’t be hitting it. as soon as the coordinates in one vector match he should be heading in a straight line.

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 * ---
 * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
 **/
class Player
{
static void Main(string[] args)
{
    string[] inputs = Console.ReadLine().Split(' ');
    int lightX = int.Parse(inputs[0]); // the X position of the light of power
    int lightY = int.Parse(inputs[1]); // the Y position of the light of power
    int initialTX = int.Parse(inputs[2]); // Thor's starting X position
    int initialTY = int.Parse(inputs[3]); // Thor's starting Y position
    //------------------\\
    int thorX = initialTX;
    int thorY = initialTY;
    // game loop
    while (true)
    {
        int remainingTurns = int.Parse(Console.ReadLine()); // The remaining amount of turns Thor can move. Do not remove this line.

        // Write an action using Console.WriteLine()
        // To debug: Console.Error.WriteLine("Debug messages...");
        if (lightX > initialTX && lightY > initialTY)
        {
            Console.WriteLine("SE");
        }
        else
        if (lightX > initialTX && lightY < initialTY)
        {
            Console.WriteLine("NE");
        }
        else
        if (lightX < initialTX && lightY < initialTY)
        {
            Console.WriteLine("NW");
        }
        else
        if (lightX < initialTX && lightY > initialTY)
        {
            Console.WriteLine("SW");
        }
        else
        if (lightX > initialTX && lightY == initialTY)
        {
            Console.WriteLine("E");
        }
        else
        if (lightX < initialTX && lightY == initialTY)
        {
            Console.WriteLine("W");
        }
        else
        if (lightX == initialTX && lightY < initialTY)
        {
            Console.WriteLine("N");
        }
        else
        if (lightX == initialTX && lightY > initialTY)
        {
            Console.WriteLine("E");
        }
        // A single line providing the move to be made: N NE E SE S SW W or NW
        //Console.WriteLine("SE");
 
    }
}
}

I am not sure why he is going past the wall, any help would be wonderful.

Standard Output Stream:

SE

Game information:

Thor's moving...
Thor position = (15,15). Light position = (36,17). Energy = 21

1619
Standard Output Stream:

SE

Game information:

Thor's moving...
Thor position = (16,16). Light position = (36,17). Energy = 20

1719
Standard Output Stream:

SE

Game information:

Thor's moving...
Thor position = (17,17). Light position = (36,17). Energy = 19

1819
Standard Output Stream:

SE

Game information:

Failure: Thor wandered off the path and died (invalid position).
Thor position = (18,18). Light position = (36,17). Energy = 19

In the above example, Thor should not have gone past the Y coordinate of 17. He should have headed straight East.

the answer is just above your post…

1 Like

:robot:

if "17" in post:
    answers = [ "You have to update Thor's coordinates."
              , "The answer is just above your post..."
              , "Do you know Thor's current position?"
              ]
    thread.reply(random.choice(answers))
2 Likes

wow! you’ve chosen my answer!

the testcases are not ideal
i passed the tests without even noticing that the game board has limited size
only noticed it because i failed the testcases in the code golf version

You cant test that. An algorithm that works on an unlimited board should also work on a limited board.

nevermind. had an error in the code golf version

I’m unable to solve this… As soon as thor hits the same X or Y coordinate as the light, the game claims he went out of bounds. Were you ever able to solve this?

Print remaining moves, Thor and light coordinates each turn, post the output here.

Is there a limitation on the functions we can use in python? I’m receiving invalid syntax for print(“S”, end=’’), which is a valid syntax for both python 2 and 3

It’s not valid in Python 2 unless you import print_function.

1 Like

Thank you. I found python3 as a language anyway, no more problems for me ^^