Power Of Thor - Episode 1 - Puzzle discussion

Hello everyone!

I’ve already solved this puzzle with a lot of “if” conditions, and i’m now trying to solve it by using a string and the command append().

It looks to be working (the Standard Output Stream gives the correct command for the first turn for all test cases), but i get the Timeout error.

Game information:

Thor’s ready to go. Thor position = (0,0). Light position = (36,17). Energy = 36

Standard Output Stream:

SE

Game information:

Timeout: your program did not provide an input in due time. Earth was destroyed! Thor position = (0,0). Light position = (36,17). Energy = 36

Why does it happen and how do i fix it?

missing “\n” …?

Hi, just trying ‘Easy Angle’ with Python3 and having no luck. I’m a complete beginner and don’t understand how to incorporate the boundary into my code.
I get this error:

Standard Output Stream:

SW

Game information:

Failure: Thor wandered off the path and died (invalid position). Thor position = (17,18). Light position = (0,17). Energy = 31

Hi! When I tried to submit my solution my third task have failed, and I don’t know why because all TC have passed.

That is message that was shown on submit - The validators differ from the puzzle test cases to prevent hard coded solutions. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.

I don’t know what does that mean, my code isn’t hardcoded for this test case.
Would be grateful for any help or ideas

Thanks

Summary

Here is my solution

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

    Integer positionX = Integer.valueOf(initialTx);

    Integer positionY = Integer.valueOf(initialTy);

    while (true) {

        int remainingTurns = in.nextInt();

        StringBuilder direction = new StringBuilder();

        int horizontalDirection = initialTx - lightX;

        int verticalDirection = initialTy - lightY;

        if (verticalDirection > 0 && positionY != 0) {

            direction.append("N");

            positionY--;

        } else if (verticalDirection < 0 && positionY != 17) {

            direction.append("S");

            positionY++;

        }

        if (horizontalDirection > 0 && positionY != 0) {

            direction.append("W");

            positionX--;

        } else if (horizontalDirection < 0 && positionX != 39) {

            direction.append("E");

            positionX++;

        } 

        System.out.println(direction.toString());

    }

}

}

Would it be more clear if the message was:

The validators differ from the puzzle test cases. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.

Sometimes, a straight line is not the right solution.

hi guys, i have solved test case #1, #2, #3 but couldn’t get #4… i am not sure what to do to improve it, my code just compares ratio of width and height and chooses which one is closest.

I cant understand why this didnt work. After the Earth was destroyed I looked at the answer to compare but I can’t find what i did wrong:

ns=''
ew=''
if initial_ty>light_y:
    ns = 'N'
    initial_ty -=1
elif initial_y<light_y:
    ns = 'S'
    initial_ty +=1

if initial_tx>light_x:
    ew = 'W'
    initial_tx -=1
elif initial_tx<light_x:
    ew='E'
    initial_ty +=1

print(ns+ew)

it is obvious …
you update “initial_ty” when moving “E” instead of “initial_tx”

Ha! You are correct sir. Feel like an idiot. Thank you

What if initial_ty==light_y?

If they are equal then neither the if or elif are true so ‘ns’ or ‘ew’ will remain ‘’. When they are concatenated at the print statement if they are both blank then Thor is already at the power.

I think you have made a mistake on one of the variable names.

How can you do that ? I tried but only got 75%

Which validator did you fail?

Hi! I’m new to coding and can’t understand why Thor isn’t moving, even with a simple code as:

if light_x > initial_tx:
print(“E”)
else:
print(“NE”)

No error, no nothing, he just wont move. So i’m very confused lol.

PS: Using Python3

PSS: Even when I use the “hint” solution code, Thor doesn’t move, is this some sort of bug or am I missing something?

Do you mean you clicked the “PLAY TESTCASE” button and nothing happened?

Yes.

Just get this: “Timeout: your program did not provide an input in due time. Earth was destroyed!”
under “Game information”

In this puzzle, you have to print a direction every turn. Does your code do that?

Well, yes, I started to doubt my own simple code just to try something more than:

print(“W”)

So I tried the “solution” code, and nothing.