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.
Same in JS
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
maan, first I didnât update thors position and then I set thors position = initialPosition before the initialPosition is initialized xP
same problem here. iâm trying to solve it on python
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.
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.
Wrote a correct code, didnât work. Copy-pasted the ââsolutionââ offered - that doesnât work either.
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?
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
seems youâre not handling correctly the direction South West. Check the replay.
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");
}
}
}
}
â==â != â=â
Check your expressions. (Assignment vs Comparison)
x = 1 is an assignment,
x == 1 a comparison
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
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.
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 ?
Yes it is a infinite loop. Dont need a exit for this program.
In the if statement : You are writing initialY instead of initialTY!
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);
}
}
}
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