Power Of Thor - Episode 1 - Puzzle discussion


#525

I got a test case
Thor position = (-1,4). Light position = (31,4)
I think x= -1 position is invalid!!!


#526

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).


#528

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…


#529

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…


#530

I had the same issue with Python3. When I test my code, I only could reach 75%. But when I submitted, I got 100%! :slight_smile:


#531

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


   
}

?>

#532

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");
    
}

?>

#533

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?


#534

Because it’s thorY-=1 (that is thorY=thorY-1), not thorY=-1 (that is thorY=-1).


#535

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++;
            }
        }

#536

Can I get some help to fix my code because I am only receiving 75% always.


#537

Are you sure that what you go North, Y increases?


#538

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.


#539

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…


#540

ohh yes thankyou!!


#541

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 ...

?>


#542

also true for Java I thought since thorY =+ 1 means thorY = thorY + 1 it would be the same.


#543

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;
}

#544

do you know Thor’s current position?


#545

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