 # Power Of Thor - Episode 1 - Puzzle discussion

Hi guys!

I don’t understand why if I remove the System.err my code doesn’t work

``````// game loop
while (true) {
int remainingTurns = in.nextInt(); // The remaining amount of turns Thor can move. Do not remove this line.

if (initialTx > lightX && initialTy == lightY) {
System.out.println("W");
} else if (initialTx < lightX && initialTy == lightY) {
System.out.println("E");
}

if (initialTy > lightY && initialTx == lightX) {
System.out.println("N");
} else if (initialTy < lightY && initialTx == lightX) {
System.out.println("S");
}

if (initialTx < lightX && initialTy < lightY) {
System.err.println("Thor position is X: " + (initialTx++) + ", Y: " + (initialTy++));
System.out.println("SE");
} else if (initialTx < lightX && initialTy > lightY) {
System.err.println("Thor position is X: " + (initialTx++) + ", Y: " + (initialTy--));
System.out.println("NE");
} else if (initialTx > lightX && initialTy < lightY) {
System.err.println("Thor position is X: " + (initialTx--) + ", Y: " + (initialTy++));
System.out.println("SW");
} else if (initialTx > lightX && initialTy > lightY) {
System.err.println("Thor position is X: " + (initialTx--) + ", Y: " + (initialTy--));
System.out.println("NW");
}
}``````

If you remove your debug printing, your position variables are no more updated.

1 Like

Hello everybody,
I’ve just starting in programming. For this exercise, i’ve looked in the clues, and the solutions it gives doesn’t pass every test when I try it; So I tried to create a another solution, but based on the first one.here it is :
if thor_x > light_x :

``````    direction_thor = "W"

thor_x -= 1

elif thor_x < light_x :

direction_thor = "E"

thor_x += 1

if thor_y > light_y :

direction_thor = "N"

thor_y -= 1

elif thor_y < light_y :

direction_thor = "S"

thor_y += 1

if thor_x > light_x, and thor_y > light_y :

direction_thor = "NW"

thor_x,thor_y -= 1

elif thor_x > light_x, and thor_y < light_y :

direction_thor = "SW"

thor_x -= 1, and thor_y += 1

if thor_y > light_y,and thor_x < light_x :

direction_thor = "NE"

thor_x += 1, and thor_y -= 1

elif thor_y < light_y, and thor_x < light_x :

direction_thor = "SE"

thor_x, thor_y += 1
``````

From the moment I write if thor_x > light_x, and thor_y > light_y : , the console tells me that it is not a function. I use python, can you help me, and tell me why it doesn’t work ?
Thanks for having read this message

I guess it’s logical that you make the exact same mistake in English and Python. So, here is the rule: there is seldom if ever a comma before the “and” conjunction in English (as well as in French by the way and probably many other languages) and never in Python (or any other programming language which uses the “and” keyword).

Next time, we will have a look on punctuation rules regarding spacing and uppercase. Unfortunately, a topic nobody cares about when coding.

1 Like

Thanks a lot

Yeah, there’s still a bug. Drove me nuts, but at least it helped me solidify some basic syntax in my mind. I ended up having to compare my code to the solution code. Basically, every bit of the code was identical, except the variable names. It kept showing expected “;” on the same line, but nothing would change the error code, even adding a “;” in random places. Only worked with a solution copy & paste.

Console output doesn’t display where the error is

What do you mean?
This is the error you have on test 3:

Im writing the code in python and got a similiar issue with case 3 and case 4 like previously mentioned.
But i cant seem to figure out why my Thor runs out of bounds.
I declared the variables outside of the loop and initiated them with 0
After getting the inputs i overwritten them with the inital_tx / ty values.
Additionaly i Checked for the conditions of my if statements. Which i cant seem to find the issue.
I get the exact error Thibaud discribes cause he wants to go another SW
and runs to position (-1,5)

Dear all,

can anyone help me with my code. I have looked to the solution and I can´t figure out what i am missing in my code.

Thank you very much

Here it is the solution I wrote:

``````import sys
import math

light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]

thor_x, thor_y = initial_tx, initial_ty

while True:
remaining_turns = int(input())  # The remaining amount of turns Thor can move. Do not remove this line.

direction_x = ""
direction_y = ""

if thor_x == light_x:
if thor_y == light_y:
elif thor_y > light_y:
thor_y -= 1
direction_y = "S"
else:
thor_y += 1
direction_y = "N"
elif thor_y == light_y:
if thor_x == light_x:
elif thor_x > light_x:
thor_x -= 1
direction_x = "W"
else:
thor_x += 1
direction_x = "E"

print(direction_x, direction_y)``````

Know that you can better format your code by manually putting it inside a code section:

````````` python
```
``````

``````import sys
import math

light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]

thor_x, thor_y = initial_tx, initial_ty

while True:
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.

direction_x = ""
direction_y = ""

if thor_x == light_x:
if thor_y == light_y:
elif thor_y > light_y:
thor_y -= 1
direction_y = "S"
else:
thor_y += 1
direction_y = "N"
elif thor_y == light_y:
if thor_x == light_x:
elif thor_x > light_x:
thor_x -= 1
direction_x = "W"
else:
thor_x += 1
direction_x = "E"
else:
do_nothing_useful_when_none_of_the_coordinates_are_ok()

print(direction_x, direction_y)
``````

Hi. I’ve resumed learning programming after so long.
Can anyone tell me why this code does not even start?

``````import java.util.*;
import java.io.*;
import java.math.*;

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

// game loop
while (true) {
int remainingTurns = in.nextInt(); // The remaining amount of turns Thor can move. Do not remove this line.

//I've tried to express "go east until the X position of Thor and Power source become the same."
Integer.valueOf(lightX);
Integer.valueOf(initialTx);
while (lightX = initialTx) {
System.out.println("E");
}
}
}
}``````

In a game such as “Power of Thor”, there are 2 actors: the simulation and your program. They interact together only through their IO (input/output), nothing else. The simulation knows nothing of your program.

When you write `int lightX = in.nextInt()`, you wait for and read an input line as an `int` to store it into a variable named `lightX`. Your variable is just a box with a value inside. Its value won’t change magically to reflect an updated Thor’s position.

So, when you later write :

``````while (lightX = initialTx) {
System.out.println("E");
}
``````

There is absolutely no way for `lightX` and `intialTx` to change. It is always false or true. In the first case you output nothing, in the second, you output an infinite sequence of `'E'`. None of these behaviors is correct.

Also, calling the `Integer.valueOf` method does nothing (it converts an unboxed value into a boxed one, but since you ignore the returned value, it doesn’t even matter). Even if calling this method was doing something useful, it wouldn’t change anything since the call is done outside the inner `while` loop.

Lastly, you can’ translate “until the X position of Thor and Power source become the same” by “while lightX equals initialTx”, it is just wrong.

1 Like

In short, my mistakes might be:
-the truth or falsehood of while loop can’t be changed
-the way of and place to write Integer.valueOf are pointless
-initialTx is starting X position of Thor, not where currently he is

I’ll try it again.

The way you put it is quite confusing. Let’s be clearer:

• Obviously, the condition of `while` loops, in general, can change. They would be mostly useless otherwise. It’s simply that, in your code, you doesn’t update anything in order to change it.
• Your usage of `Integer.valueOf` is obviously pointless. What do you hope to achieve by using it?
• Your `intiatTx` is initialized with Thor’s starting position and you do not change it, so it stays this way. If you were trying to update it in your loop, it could be the updated Thor’s position. Once again, its your choice. By the way, your inner loop is completely unnecessary.

It’s hard to put yourself in someone else’s mind, but it seems like you are not programming, but simply stating facts (or rules) for Thor to follow. That’s not how it works. You can’t code abstract things such as “this is Thor position, whatever it is” or “go east until Thor and the light share the same x coordinate”. These kind of sentences describe your goal, not how to actually do it (in other words, it’s a specification, not an implementation).

If it could help you, here’s how your goal of “going east until Thor and the light share the same x coordinate” could be implemented:

``````public static void main(String args[]) {
Scanner in = new Scanner(System.in);

final int lightX = in.nextInt(); // the X position of the light of power
final int lightY = in.nextInt(); // the Y position of the light of power
final int initialTx = in.nextInt(); // Thor's starting X position
final int initialTy = in.nextInt(); // Thor's starting Y position

int thorX = initialTx;

// game loop
while (lightX != thorX) {
// In this specific contest, the turn's input is not useful and you don't neet to read it.
final int remainingTurns = in.nextInt();

System.out.println("E");
thorX = thorX + 1;

System.err.println("Before looping: thorX == " + thorX);
System.err.println("Before looping: (lightX != thorX) == " + (lightX != thorX));
}
}
``````
1 Like

Hello Can anybody help me pls with this 75%-Case? I really dont understand what is wrong with my code “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.”

How can i get help without posting my code ?

it’s highly probable you find a hint if you read back a few messages in this thread.

The replay of the validators can also give you an idea of what’s wrong in your code.

You can tell us what your algorithm does.

Good luck!

Ahhh thanks for your response The replay helped me finding a the mistake! Thanks!!!

*as always… it was too easy to find it in the beginning *

1 Like

The hidden TestCase EasyAngel is error? My Thor went over the Light and it didn’t pass!

Hi all!
I got problem while running this game in Haskell:
This is my code, it should work just fine, and I test it on my VScode it runs on demand
But it runs different in Game.
Anyway this is my code :

``````putStrLn (determ initialtx lightx initialty lighty)

determ :: Int -> Int -> Int -> Int -> String

determ a b c d

| x > 0  && y > 0  = "SE"

| x > 0  && y < 0  = "NE"

| x < 0  && y > 0  = "SW"

| x < 0  && y < 0  = "NW"

| x == 0 && y < 0  = "N"

| x == 0 && y > 0  = "S"

| x > 0  && y == 0 = "E"

| x < 0  && y == 0 = "W"

where

x = b - a

y = d - c``````