I got a test case
Thor position = (-1,4). Light position = (31,4)
I think x= -1 position is invalid!!!
This is the result of what your algorithm does. Just above, you have this sentence:
Failure: Thor wandered off the path and died (invalid position).
Hi, I donât know if any of this happened to you guys but this puzzle doesnât work when providing a solution in Python3. I even checked with the given solution and it still return some errorsâŚ
I tried using C now, and the same happens, although this time the given solution does work, but mine doesnât even though itâs the same⌠Maybe I just canât read or something.
SOLVED
Aparently itâs an error to declare things like char solutionX = " ";
instead of
char solutionX = "";
So⌠yep⌠and it also magically works in python3 aswellâŚ
I had the same issue with Python3. When I test my code, I only could reach 75%. But when I submitted, I got 100%!
Can anyone help me out, figuring out what is wrong with my code
<?php
/**
* 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.
**/
fscanf(STDIN, "%d %d %d %d",
$lightX, // the X position of the light of power
$lightY, // the Y position of the light of power
$initialTX, // Thor's starting X position
$initialTY // Thor's starting Y position
);
// game loop
while (TRUE)
{
fscanf(STDIN, "%d",
$remainingTurns // The remaining amount of turns Thor can move. Do not remove this line.
);
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));
// A single line providing the move to be made: N NE E SE S SW W or NW
$lx = $lightX;
$ly = $lightY;
$thorx = $initialTX;
$thory = $initialTY;
if($ly < $thory){
echo("N");
--$thory;
}
elseif($ly > $thory){
echo("S");
++$thory;
}
if($lx < $thorx){
echo("W");
--$thorx;
}
elseif($lx > $thorx){
echo("E");
++$thorx;
}
echo("\n");
}
?>
I just put your code snippet into PHP Formatter (first thing Iâve found on Google). Is it a lot nicer now? As a bonus, your error better stands out now.
<?php
/**
* 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.
**/
fscanf(STDIN, "%d %d %d %d", $lightX, // the X position of the light of power
$lightY, // the Y position of the light of power
$initialTX, // Thor's starting X position
$initialTY // Thor's starting Y position
);
// game loop
while (TRUE) {
fscanf(STDIN, "%d", $remainingTurns // The remaining amount of turns Thor can move. Do not remove this line.
);
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));
// A single line providing the move to be made: N NE E SE S SW W or NW
$lx = $lightX;
$ly = $lightY;
$thorx = $initialTX;
$thory = $initialTY;
// Maybe I should print some things on STDERR to debug my program?
if ($ly < $thory) {
echo ("N");
--$thory;
}
elseif ($ly > $thory) {
echo ("S");
++$thory;
}
if ($lx < $thorx) {
echo ("W");
--$thorx;
}
elseif ($lx > $thorx) {
echo ("E");
++$thorx;
}
echo ("\n");
}
?>
In C++
When I try to update thorY like this
thorY=-1;
it doesnât work all the time
but when I wrote it out it did
thorY=thorY-1;
I thought these were the same, why isnât the first working?
Because itâs thorY-=1 (that is thorY=thorY-1), not thorY=-1 (that is thorY=-1).
I have a question about my code. Everything works except the optimal angle when i submit my code. The optimal angle within the IDE works though.
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
int distanceX=0;
int distanceY=0;
int counterX=0;
int counterY=0;
// 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
distanceX= (lightX-initialTX);
distanceY= (lightY-initialTY);
if((Math.abs(distanceX) + Math.abs(distanceY))>=remainingTurns && counterX < distanceX && counterY < distanceY && lightY>initialTY && lightX>initialTX){
System.out.println("SE");
counterX++;
counterY++;
}
else if(counterX < distanceX) {
System.out.println("E");
counterX++;
}
else if((Math.abs(distanceX) + Math.abs(distanceY))>=remainingTurns && counterX < distanceX && counterY < distanceY && lightY<initialTY && lightX<initialTX){
System.out.println("NE");
counterX++;
counterY++;
}
else if((Math.abs(distanceX) + Math.abs(distanceY))>=remainingTurns && counterX < distanceX && counterY < distanceY && lightY>initialTY && lightX<initialTX){
System.out.println("SW");
counterX++;
counterY++;
}
else if(counterX<Math.abs(distanceX)){
System.out.println("W");
counterX++;
}
else if(counterY<distanceY) {
System.out.println("S");
counterY++;
}
else if((Math.abs(distanceX) + Math.abs(distanceY))>=remainingTurns && counterX < distanceX && counterY < distanceY && lightY<initialTY && lightX>initialTX){
System.out.println("NW");
counterX++;
counterY++;
}
else if(counterY>Math.abs(distanceY)){
System.out.println("N");
counterY++;
}
}
Can I get some help to fix my code because I am only receiving 75% always.
Are you sure that what you go North, Y increases?
Yes counterY updates when i go North but the problem occurs when I GO West. When I proceed to go west, the program cannot stop going West and causes Thor to exceed the bounds of the map.
The check for going SW isnât checking the X-axis the same as the check for going W. The one going W seems to work, soâŚ
ohh yes thankyou!!
with the php language at the third testcase is a bug, with the code below I solve the first and second testcase, but the third and fourth is impossible, my variable âtorXâ is increasing in one turn from 4 to 17 for the third level, and for the fourth the programm doesnât change direction, it goes in the opposit direction:
<?php
fscanf(STDIN, "%d %d %d %d",
$lightX, // the X position of the light of power
$lightY, // the Y position of the light of power
$initialTX, // Thor's starting X position
$initialTY // Thor's starting Y position
);
$torX = $initialTX;
$torY = $initialTY;
$turn = 0;
$s = 0;
$n = 0;
while (TRUE)
{
$turn++;
$x = "";
$y = "";
if($torX < $lightX){
$x = "E";
$torX = $torX + 1;
}elseif($torX > $lightX){
$x = "W";
$torX = $torX - 1;
}
if($torY < $lightY){
$y = "S";
$torY += $torY + 1;
$s = $s + 1;
}elseif($torY > $lightY){
$y = "N";
$torY = $torY - 1;
$n = $n + 1;
}
if($turn < 13 && $torY == 17){
$torY -= $turn;
}
echo($y.$x."\n");
error_log(var_export($torY, true));
}
and the ouput:
Standard Error Stream: 9 19 18 13 27 26 25 24 23 22 21 20 19 18 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ...
?>
also true for Java I thought since thorY =+ 1 means thorY = thorY + 1 it would be the same.
what is wrong with this code?
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);
// game loop
while (1)
{
int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
scanf("%d", &remainingTurns);
if(initialTY>lightY&&initialTX<lightX)
{
printf("NE\n");
}
else if(initialTY<lightY&&initialTX>lightX)
{
printf("SW\n");
}
else if(initialTY>lightY&&initialTX>lightX)
{
printf("NW\n");
}
else if(initialTY<lightY&&initialTX<lightX)
{
printf("SE\n");
}
else if(initialTX<lightX)
{
printf("E\n");
}
else if(initialTY<lightY)
{
printf("S\n");
}
else if(initialTY>lightY)
{
printf("N\n");
}
else
{
printf("W\n");
}
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
// A single line providing the move to be made: N NE E SE S SW W or NW
}
return 0;
}
do you know Thorâs current position?
Hello guys, i have one problem in 3 test cases. I checked will the Thor change direction.
Thor start position
Thorâs ready to go.
Thor position = (31,4). Light position = (0,17). Energy = 44
My code
while (true){
if (initialTY >= 10)
System.out.println("W");
else System.out.println("S");
}
Thor didnât change direction. His last position.
Failure: Thor wandered off the path and died (invalid position).
Thor position = (31,18). Light position = (0,17). Energy = 31