Power Of Thor - Episode 1 - Puzzle discussion


#656

Coordinates 0,0 are in the top-left corner, so going North will reduce your Y-coordinate by 1. This is standard in computer graphics.


#657

Same in JS


#658

I wish it would specify in description that Thor’s coordinate’s aren’t updated automatically.
I thought “starting coordinates” were for each turn of the game


#660

maan, first I didn’t update thors position and then I set thors position = initialPosition before the initialPosition is initialized xP


#661

same problem here. i’m trying to solve it on python


#662

Hey, i solved it. You have to update thor’s coordinates in every move. Thor’s coordinates in the input doesn’t change, it only gives you the first coordinates of Thor.


#663

was getting frustrated so i copy pasted the solution to make sure it was possible. still doesn’t reach his goal on the last two tests…using swift.


#664

Wrote a correct code, didn’t work. Copy-pasted the ‘‘solution’’ offered - that doesn’t work either.


#665

The given solution works for me. Seems you made a mistake while copy pasting. Does the pseudo-code and the solution help you understand what’s wrong in your code?


#666

Same to java, during testing all tests passed, and in submitting the last one is not working https://gyazo.com/bbba7537617c392f11ec54ff0d677d6b
https://gyazo.com/f4dbfc89804e5513b31be85874902425


#667

seems you’re not handling correctly the direction South West. Check the replay.


#668

I have no idea what is this error( error: bad operand types for binary operator ‘&&’ if((lightX > initialTX && lightY = initialY))

This 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

        // 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...");


            // A single line providing the move to be made: N NE E SE S SW W or NW
          if(lightX > initialTX && lightY = initialY)
             {
            
            System.out.println("E");
             }
             else if(lightX < initialTX && lightY = initialY)
             {
                 System.out.println("W");
             }
             else if(lightX = initialTX && lightY > initialY)
             {
                 System.out.println("N");
             }
             else if(lightX = initialTX && lightY < initialY)
             {
                 System.out.println("S");
             }
             else if(lightX < initialTX && lightY < initialY)
             {
                 System.out.println("SW");
             }
             else if(lightX < initialTX && lightY > initialY)
             {
             System.out.println("NW");
             }
             else if(lightX > initialTX && lightY > initialY)
             {
                 System.out.println("NE");
             }
             else if(lightX > initialTX && lightY < initialY)
             {
                 System.out.println("SE");
             }
             
        }
    }
}

#669

“==” != “=”

Check your expressions. (Assignment vs Comparison)
x = 1 is an assignment,
x == 1 a comparison


#671

I have absolutely no clue on how to do the whole angles bs, I got the straight line and up testcases figured out, but I have no clue how to do the angle testcases


#672

Try this:

Create an empty string.
If the y-coordinate is not the same as the target y-coordinate, make the string N or S, as appropriate.
If the x-coordinate is not the same as the target, add E or W to the string.
Output the string.
Don’t forget to update your position.


#674

I’m a begginier.
Please help me.
In python, I dont undertsand while 1 :
Why 1 ? what’s this condition ? I dont understant why it is not an infinite loop ? because 1 is always true ?


#675

Yes it is a infinite loop. Dont need a exit for this program.


#676

In the if statement : You are writing initialY instead of initialTY!


#677

I dont understand whats going wrong with my code.
It seems only once the loop is getting iterated as only one character is getting printed. Please help me out.

import java.util.*;
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
        while (true) 
        {
            int remainingTurns = in.nextInt(); 
            String dirX="";
            String dirY="";
                if(initialTY<lightY)
                {
                    dirY= "S";
                    initialTY++;
                }
               else if(initialTY>lightY)
                {
                    dirY="N";
                    initialTY--;
                }
                if(initialTX<lightX)
                {
                    dirX="E";
                    initialTX++;
                }
               else if(initialTY>lightX)
                {
                    dirX= "W";
                    initialTX--;
                }
            System.out.print(dirY+dirX);
        }
    }
}

#678

Check your IFs, you mixed X and Y somewhere…

And try println instead of print…

Every now and then use System.err.println(); for debug, sometimes it helps