Power Of Thor - Episode 1 - Puzzle discussion

Good evening!

I have some question about how to complete the easy angle case wisely: I did it with a lot of syso with empirical test each time and that seems not to be the right way to do, is there a wiser way to achieve it?

I’m only asking for hints! I’m here to learn!

Here is my code:

`import java.util.*;
import java.io.*;
import java.math.*;

/**
 * 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 {

    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
        double i=14;
        
        // 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 (lightY==initialTY){
                System.out.println("SE"); // A single line providing the move to be made: N NE E SE S SW W or NW
                System.out.println("NE");
            }
            if(lightX==initialTX){
                System.out.println("N");
            }
            
            if((lightX<initialTX)&&(lightX<initialTX)&&(i>0)){
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("NW");
                System.out.println("NW");
                System.out.println("NW");
                System.out.println("NW");
                System.out.println("NW");
                System.out.println("NW");
                System.out.println("NW");
                System.out.println("NW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("SW");
                System.out.println("NW");
                System.out.println("SW");

                i--;
                System.err.println("i: " + i);
            }

        }
    }
}`

There must be a bug with this game.
When I play all test cases all of them pass correctly but when I submit the easy angle keeps failing even though I see how Thor passes over the light. You can see what I mean here: https://imgur.com/PZlj4ea

I need help on eagle case.
I’ve tried everything I even tried to copy and paste your solution but is not working.
when thor reaches y=17 instead of going W or E he goes SW. Why?? is there a bug in the game? I’m using python. Help

Hey I need some help, I don’t understand why Thor don’t move just a little bit. Thank you very much for help me.

int main()
{
int lightX; // the X position of the light of power
int lightY; // the Y position of the light of power
int initialTX; // Thor’s starting X position
int initialTY; // Thor’s starting Y position
scanf("%d%d%d%d", &lightX, &lightY, &initialTX, &initialTY);

while (1) {
    int remainingTurns; 
    scanf("%d", &remainingTurns);
    int CoordX;
    int CoordY;
    CoordX = lightX - initialTX;
    CoordY = lightY - initialTY;
    while (CoordX != 1 || -1 ||0){
        if ( CoordX < -1){
            CoordX = CoordX + 1;
            }
        else if ( CoordX > 1){
            CoordX = CoordX - 1;
            }
        else{}    
    }
    while (CoordY != 1 || -1){
        if ( CoordY < -1){
            CoordY = CoordY + 1;}
        else if ( CoordY > 1){
            CoordY = CoordY - 1;}
        else{}           
    }
    if ( CoordX == 1 && CoordY == 0){
        printf("E\n");}
    else if (CoordX == 1 && CoordY == 1){
        printf("SE\n");}
    else if (CoordX == 1 && CoordY == -1){
        printf("NE\n");}
    else if (CoordX == 0 && CoordY == 1){
        printf("S\n");}
    else if (CoordX == 0 && CoordY == -1){
        printf("N\n");}
    else if (CoordX == -1 && CoordY == 0){
        printf("W\n");}
    else if (CoordX == -1 && CoordY == -1){
        printf("NW\n");}
    else {
        printf("SW\n");
    }
    // Write an action using printf(). DON'T FORGET THE TRAILING \n
    // To debug: fprintf(stderr, "Debug messages...\n");
    printf("N\n");
    // A single line providing the move to be made: N NE E SE S SW W or NW
    
}

return 0;

}"

@infyre, as far as I can see your program has an infinite loop, when you say:
“while (CoordX != 1 || -1 ||0)”, C does not read this as “if x does not equal 1 or not equals negative 1 or not equal 0”, it instead reads it as “if (x does not equal 1) or (negative 1) or (zero)” as three separate conditions and subsequently if there is an “or -anything that is non zero-” in your condition it will always execute.
Thus your line should be: " while (CoordX != 1 || CoordX != -1 || CoordX != 0)" as far as I understand your logic.
I hope this helps :slightly_smiling:

I happen to have my own problem though :stuck_out_tongue:
I have started learning C++ and I either don’t understand it very well or I have found a bug:
I declare two variables to hold my movements in:
“char x, y;”
In my if statements I then give them values:
“x = ‘E’;” (for example)
I then try to print them:
cout << y << x << endl;
But get this error:

Standard Output Stream:
E
Game information:
Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found ‘E’

Any thoughts? :slightly_smiling:

see here: Suggestion: include unprintable characters in the error messages

1 Like

It would need no two level(X and Y) condition check if we use string stacking.

C# codes -
string direction = “”;
direction += ThorY > lightY ? “N” : ThorY < lightY ? “S” : “”;
direction += ThorX > lightX ? “W” : ThorX < lightX ? “E” : “”;

And output the string.

My code does not pass first test: Straight Line.

This is the test and result:

Game information:
Thor’s ready to go.
Thor position = (5,4). Light position = (31,4). Energy = 100
Standard Output Stream:
E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E
Game information:
Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found ‘E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E’
Thor position = (5,4). Light position = (31,4). Energy = 100


Thor’s and Light’s Y coordinate are same. So, it should only go towards East which my code returns. I don’t understand why it is failing.

You have to are supposed to print one direction and a newline per step. Not all directions at once in the first step.

That’s not true, i can do print(“E\nE\nE\n”); and I will go East for the next three turn.

The point is @hakanlar you need a line feed ‘\n’ of std::endl, or whatever language you are using to end one line after each action

Where is the input? I don’t see it on my screen.

Shouldn’t the direction N add 1 to thor’s Y coordinate? In the solution, the following is written:
if (thorY > lightY){ directionY = "N"; thorY = thorY - 1; }else if(thorY < lightY){ directionY = "S"; thorY = thorY + 1; }
which means that if thor is above the light, his Y cord. should be decrementing by 1, which is implemented in the code but the direction is N instead of S.
Is that a bug? N should add 1 and S removes 1…

That just says that the light’s Y-cord is the same as the Y-cord for Thor/initial.

From the puzzle description : Note that the coordinates (X and Y) start at the top left! This means the most top left cell has the coordinates “X=0,Y=0” and the most bottom right one has the coordinates “X=39,Y=17”
So going north decreases the value of Y.

That makes perfect sense, thank you!

hi brother how can i do it ?

I got 100% in Java … :dsunglasses:

Hey guys I’m running into an issue on Test Case 03

In C++ when doing a variable compare is it just less than or less than and equal to when using “<”
My code is below for your referance; my problem is when Thor is on the same axis as the light he continues to move

#include
#include
#include
#include

using namespace std;

/**

  • 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.
    **/
    int main()
    {
    int lightX; // the X position of the light of power
    int lightY; // the Y position of the light of power
    int initialTX; // Thor’s starting X position
    int initialTY; // Thor’s starting Y position
    cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();
    int cpositionX = initialTX;
    int cpositionY = initialTY;

    // game loop
    while (1) {
    int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
    cin >> remainingTurns; cin.ignore();
    string moveT = “”; //the way Thor should move

     if (cpositionY < lightY){
         cpositionY --;
         moveT = "S";
     } else if (lightY < cpositionY){
         cpositionY ++;
         moveT = "N";
         }
         
     if (lightX < cpositionX){
         cpositionX --;
         moveT = moveT + "W";
     } else if (lightX > cpositionX){
             cpositionX ++;
             moveT = moveT + "E";
         }
     
    
     // Write an action using cout. DON'T FORGET THE "<< endl"
     // To debug: cerr << "Debug messages..." << endl;
    
    
     // A single line providing the move to be made: N NE E SE S SW W or NW
     cout << moveT << endl;
    

    }
    }

Why and how to update it?

The server give you the initial position of Thor (before the game loop). During the game, the server doesn’t provide the current thor position so you have to keep track of your movement to reach the light.

NORTH means going TOP, so ThorX will decrease and so one. Take a look at the statement below the viewer for more info.