Power Of Thor - Episode 1 - Puzzle discussion


#746

I don’t think the issue is fixed, it’s stuck calculating my score too


#747

Oh nevermind, it appears to have resolved itself after about 15 minutes


#748

I think there is a bug. I’m running out of my 14 turns. Even with a simple diagonal angle to the light, and simply hardcoded go SW I can’t read the target within 14 turns.

Looks like the target is too far to ever reach.


#749

this puzzle was one of the oldest of CG.
it is solved by 237882 players.

there is no bug in the puzzle.
there is no test/validator limited to 14 turns to reach target.


#750

Looks fine to me


#751

I also had the same reaction. I started this game with Java to restart to be a developper :slight_smile: and my first test was not good, because “time out” = need to be done in 14 turns.
I just tell that because dwarfie seems very confident, but, maybe something to check.
I’ll retry it today :wink:


#752

I found 5 minutes to finish it. Yes, there is no limits on the number of turns. Maybe, the 14 we found was more because we did the same bug and so to avoid to have an infinite loop we had a time out? So maybe, just the “exception” is not clear :wink:


#753

If you hardcode SW, you get this error:

Failure: Thor wandered off the path and died (invalid position).

Try updating Thor’s coordinates.


#754

else if (thorY < lightY && thorY < 17) {
directionY = “S”;
thorY++;
I am failing the 3rd test because thorX and thorY are out of scope. I’m struggling to figure out how to update thors position inside the while loop, any tips?


#755

I’m a little confused -
For the 3rd and 4th tests, why is Thor suddenly walking in the opposite direction. According to the code, he should be walking towards the energy source, but he’s walking away from it.

I’m having the same problem on submission.
Edit : Nevermind, I found the problem. I miswrote the code. But now apparently I have to update Thor’s current position for the diagonal tests, and I have no idea how to do that.


#756

Hello,
Why in test 4 exemple has 36 steps and in javascript developmet has 14?


#757
   i realy dont get why this wont work...?

"error: variable directionX might not have been initialized

        System.out.println(directionX+directionY);
                           ^

while (true) {

       int remainingTurns = in.nextInt();// The remaining amount of turns Thor can move. Do not remove this line.
       String direction;
       
       if(dify==0){
           if(initialTx<lightX){
                directionX="";
                directionY="E";
                initialTx++;}
             else{
                 directionX="";
                 directionY="W";
                 initialTx--;
                 }
               }
       else if(difx==0){
           if(initialTy>lightY){
                directionX="N";
                directionY="";
                initialTy++;}
             else{
                 directionX="S";
                 directionY="";
                 initialTy--;
             }
       }
       else if(difx!=0&&dify!=0){
           if(initialTx<lightX&&initialTy<lightY){
           directionX="S";
           directionY="E";
           initialTx++;
           initialTy++;
           }
           else if(initialTx<lightX&&initialTy>lightY){
               directionX="N";
               directionY="E";
               initialTx++; 
               initialTy--;}
            else if(initialTx>lightX&&initialTy<lightY){
                directionX="S";
                directionY="W";
                initialTx--;
                initialTy++;}
            else{
                directionX="N";
                directionY="W";
                initialTx++;
                initialTy++;}
                }
            else{
                remainingTurns++;
                }

        // Write an action using System.out.println()
        // A single line providing the move to be made: N NE E SE S SW W or NW
        System.out.println(directionX+directionY);
    }
}

}


#758

Because the Java compiler cannot prove the variable has a value due to the if-statements. Explicitly defining it as null or an empty string should work.


#761

This is not evident from the given instructions (that we have to first print the move and then update the coordinates).
Why would it be wrong if I first update the coordinates and then print a move?
I should be able to solve this question without knowing the details of how the solution checker is working to check my solution.


#762

I don’t know which post you’re replying to (I went back a couple of months but couldn’t find it), but if I gave you the impression that it matters when you update your internal variables, I apologize.

All the checker cares about is what you output to it. You can update the variables any way you choose and at any time. Some people don’t even bother with position tracking and use loops instead.

edit: Found it. The problem with the code I was commenting on was that he was updating his coordinates before he even decided which direction was the correct one to go. So his directions were always one turn ahead of where he actually was.


#763

Swift solution_

[Erm, no]


#765

You can click on the Reply Icon and see what they answered to. (On the post itself, which pops up, you can also click on the little arrow to “scroll up” to that exact post)
It’s a post “First, move. THEN update coordinates.” from you where you answered to someone who updated their coordinates first, then checked in which direction they have to move.
No, it doesn’t matter in which order you do what, as long as you reach the goal in the given moves.

@saurabhrk:
The solution checker checks only whether Thor is on a given coordinate when his allowed movecount has reached 0 or he is on the given coordinate earlier.