while (1) {
int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
scanf("%d", &remainingTurns);
char *directionX = ""; <===== How this work, why pointer to double comma cause, saving places of thor?
char *directionY = "";
if (thorY > lightY) {
directionY = "N"; <===== and how this connects with this double comma N?
thorY--;
Is there a bug in Java version? I have solved this in c# and code working ok
in the 3rd test there are 36 moves to complete the level but in Java there are only 18 moves
so you cant complete the level.
Hey, friends!I am new to coding and JS.Could someone explain why this code doesn’t work for easy and optimal angels?This is my second time solving this task.For the first time I solved it correctly with if,else if, else.Then I decided to find an other way but it didn’t work.
var inputs = readline().split(’ ');
const LX = parseInt(inputs[0]); // the X position of the light of power
const LY = parseInt(inputs[1]); // the Y position of the light of power
const TX = parseInt(inputs[2]); // Thor’s starting X position
const TY = parseInt(inputs[3]); // Thor’s starting Y position
let tx=TX, ty=TY;
while (true) {
const remainingTurns = parseInt(readline());
let dirX=‘’, dirY=‘’;
You would find using console.error useful in helping you to debug, e.g. adding this line after let dirX='', dirY='';: console.error(tx + ' ' + ty);
It prints out the values of the variables so that you know where they are different from your expected values.
By the way, please format your code properly on this forum by using the </> button in the formatting toolbar.
while (true) {
const remainingTurns = parseInt(readline()); // The level of Thor’s remaining energy, representing the number of moves he can still make.
const routeT = ‘’;
if ( LX < TX && LY > TY) {
routeT = 'SW';
} else if ( LX > TX && LY < TY ) {
routeT = 'NE';
} else if (LY < TY && LX < TX) {
routeT = 'NO';
} else if ( LY < TY && LX > TX ) {
routeT = 'SE';
} else if ( LX == TX && LY > TY ) {
routeT = 'S';
}else if ( LX == TX && LY > TY ) {
routeT = 'N';
} else if ( LY == TY && LX > TX ) {
routeT = 'W';
} else if ( LY == TY && LX > TX ) {
routeT = 'O';
}
const remainingTurns = parseInt(readline()); // The level of Thor’s remaining energy, representing the number of moves he can still make.
let routeT = ‘’;
let positionTX = TX;
let positionTY = TY;
if ( LX < TX && LY > TY) {
routeT = 'SW';
positionTX--;
positionTY++;
} else if ( LX > TX && LY < TY ) {
routeT = 'NE';
positionTX++;
positionTY--;
} else if (LY < TY && LX < TX) {
routeT = 'NW';
positionTX--;
positionTY--;
} else if ( LY > TY && LX > TX ) {
routeT = 'SE';
positionTX++;
positionTY++;
} else if ( LY > TY ) {
routeT = 'S';
positionTY++;
}else if ( LY < TY ) {
routeT = 'N';
positionTY--;
} else if ( LX > TX ) {
routeT = 'E';
positionTX++;
} else if ( LX < TX ) {
routeT = 'W';
positionTX--;
}
while (true) {
const remainingTurns = parseInt(readline()); // The level of Thor's remaining energy, representing the number of moves he can still make.
let routeT = '';
let positionTX = TX;
let positionTY = TY;
if ( LX < TX && LY > TY) {
routeT = 'SW';
positionTX--;
positionTY++;
} else if ( LX > TX && LY < TY ) {
routeT = 'NE';
positionTX++;
positionTY--;
} else if (LY < TY && LX < TX) {
routeT = 'NW';
positionTX--;
positionTY--;
} else if ( LY > TY && LX > TX ) {
routeT = 'SE';
positionTX++;
positionTY++;
} else if ( LY > TY ) {
routeT = 'S';
positionTY++;
}else if ( LY < TY ) {
routeT = 'N';
positionTY--;
} else if ( LX > TX ) {
routeT = 'E';
positionTX++;
} else if ( LX < TX ) {
routeT = 'W';
positionTX--;
}
// Write an action using console.log()
// To debug: console.error('Debug messages...');
// A single line providing the move to be made: N NE E SE S SW W or NW
console.log(routeT);
}
You are never updating the position of Thor, since all your checks are using TX & TY and since they are never updated it’s like Thor is always at the starting position.
Just make sure TX & TY are defined as “let” and not “const” and simply replace all the positionTX by TX and positionTY by TY, you should also drop the lines creating positionTX & positionTY as you don’t need these variables.
The 3rd and 4th tests cannot be done
Test 1 starts Thor 26 places away and gives you 26 steps to succeed
Test 2 starts Thor 13 places away and gives you 13 steps to succeed
Test 3 starts Thor 31 places away but only gives you 14 steps
Test 4 starts Thor 36 places away but only gives you 18 steps
Or have I missed something?
i made this code but thor only moves up and down why
import sys
import 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.
# light_x: the X position of the light of power
# light_y: the Y position of the light of power
# initial_tx: Thor's starting X position
# initial_ty: Thor's starting Y position
light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
# game loop
while True:
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
dif_y = light_y - initial_ty #Y Anteil des Vektors berechnen
dif_x = light_x - initial_tx # same für X
#straight = math.sqrt(dif_y*dif_y+dif_x*dif_x) # berechnen der länge des Vektors
#schräge bewegungen
if dif_y < 0 & dif_x < 0:
print ("NW")
if dif_y > 0 & dif_x < 0:
print ("SW")
if dif_y > 0 & dif_x > 0:
print ("SE")
if dif_y < 0 & dif_x > 0:
print ("NE")
#gerade Bewegungen
if dif_y == 0 & dif_x > 0:
print ("E")
if dif_y == 0 & dif_x < 0:
print ("W")
if dif_y < 0 & dif_x == 0:
print ("N")
if dif_y > 0 & dif_x == 0:
print ("S")