Power Of Thor - Episode 1 - Puzzle discussion

Ah yes…
So much detail to check out…
Thank you for you quick answer. You’re great.

1 Like
  • Part of the Two Conditions python solution
def get_value(c1, c2, value1, value2):
    if value1[0] < value2[0]:
        value1[0]+=1
        return c1
    elif value1[0] > value2[0]:
        value1[0]-=1
        return c2
    return ''

I am kinda confused. I was able, to create a code, that solves theoraticly all puzzles. But because of the shape of the boundary, it doesn`t work. Are you supossed to create a different solution, for every puzzle or is there a solution for all puzzles? if it helps, here is my code:

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

        String directionX = "";
        String directionY = "";
        double distanceX = 0;
        double distanceY = 0;
        double endDistance = 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...");

                directionX = "";
                directionY = "";
                
                if (lightX < initialTx){
                    initialTx --; directionX = "W";
                }
                
                if (lightX > initialTx){
                    initialTx --; directionX = "E";
                }
                
                if (lightY < initialTy){
                    initialTy --; directionY = "N";
                }
                
                if (lightY > initialTy){
                    initialTy --; directionY = "S";
                }

System.err.println("initial X: " + initialTy);
System.err.println("initial y: " + initialTx);
System.err.println("direction X: " + directionY);
System.err.println("direction Y: " + directionX);
System.err.println("direction Y: " + directionX + directionY);
                
                System.out.println(directionY + directionX);
                
        }
    }
}

thx for any help

Two of the --s should be ++s instead.

Oh, thanks for the help. but it should be ++E insted of --E, right?

I’m not talking about directions there :sweat_smile: The “s” in “--s” just indicates the plural form.

I don’t know. I initially defined two functions and i went over it a hundred times, it would only run the straight lines. so i dumped the functions and had it do the same thing, just loop through the full thing instead of print(funcA(y,yy)+funcB(x,xx)) and it wwas still broken. I know the grid gives North a negative value. Actually funny enough the first time i tried this I did not read that part and I was doing arc tangents to get headings lol. anyways, i had to workaround by making him just drop whatever he was doing and start walking west until the sun goes down if he hits one particular coordinate that seemed to be breaking it. I tried doing a +1 on the comparison in general, just for that value… the only thing, literally the only thing that worked was to just force him out if he hit that coordinate

ok so i nearly pulled my hair out, what little i have, doing this but there is a key concept that fixed my issues. i was unaware that the y axis, north and south, does not move the way you learned in math class. as a point moves up the y axis is actually moving down so i had to update as such and boom 3 hours and some reading later it works for all test cases. if(ty>ly){fly=‘N’;ty --;} else if (ty<ly) {fly=‘S’;ty ++;} in case this helps any one because i almost lost all of my cool. it still barley makes sense to me but im thinking of it as the world moving instead of you.

I don’t understand how it’s all connected, I understand how your solution works, the movement will be along the axes as long as the condition is met, but I don’t understand how to solve it myself, I only had the mind to do one option, but I don’t understand how to do everything, I tried through if light_tx ==5 light_ty== 4 , but that didn 't work either

You have to generalise the situation.

Going through each possibility one by one:

  • If your destination is east of you, you have to go east.
  • If your destination is west of you, you have to go west.
  • If your destination is north of you, you have to go north.
  • If your destination is south of you, you have to go south.
  • If your destination is not one of the above, you have to go some combination of directions, e.g. northwest, northeast, southwest, southeast.
1 Like

I did this: I typed print (“E”) 4 times for the first option, but the other options seem to require a separate program.
For example, like this?:
“”"
if light_x, light_y==“W”:
print(“W”)
print(“W”)
print(“W”)
print(“W”)
“”"
?
i didn’t understand anything

You need something like this:

while I have not reached my destination:
    if my destination is east of me:
       I go east
    else if my destination is west of me:
       I go west
    else if (etc.)

How do you know the destination is east/west/north/south of you? One way to do so is to compare the x-coordinates and the y-coordinates.

Hope this gives you a better idea. If not, please let me know what you don’t understand.

P.S. 1 I corrected my last message… Sorry about my silly mistake.

P.S. 2 I’m sorry for editing your message by mistake. The forum went haywire for a moment.

I tried it like this:
“”"
while initial_tx!=light_x:
if initial_ty!=light_y:
print(“E”)
“”"
and zero an as a result

  1. Unequal x-coordinates imply the direction to go may be east or west. You have to do a more detailed comparison to know which direction to go.

  2. Unequal y-coordinates imply the direction to go may be north or south. You have to do a more detailed comparison to know which direction to go.

  3. Stick to the original code and modify from there. You are supposed to read the input each turn before you output the direction for that turn. Don’t do another while within the original while loop.

Sorry, I can’t think of anything.
the end point of movement by numbers is set arbitrarily, movement by lines is set, and after that it is somehow unclear what to set in the condition, I understood in the output that a separate print() should be written for each case, but how to write in the condition so that the point should move in any direction to the end point? I can only copy your version from the suggestions.

Thor always moves one unit per turn in the direction where you want him to go, and you have to keep track of his coordinates yourself.

Think of it this way: at the beginning, you’re given the coordinates of Thor’s initial position and the coordinates of the final position. Although they’re different in each test case, you’re always able to calculate on-the-spot which directions you should ask Thor to go in order to reach the destination.

forgive me for changing it (the neural network wrote a lot of nonsense), so the problem is that I don’t understand how to connect variables in the condition, it’s too unclear what exactly to compare with what, please give me simpler tasks because this one with coordinates and the task of movement via “print()” is absolutely incomprehensible.

You may either search “Power of Thor CodinGame” on YouTube to look for a relevant video, watch it to get a basic idea of what you’re being asked to do, or just try another puzzle and return to this one later.

Continuing the discussion from Power Of Thor - Episode 1 - Puzzle discussion:

Hi,

I got a question. I tried solving this puzzle in Java and i cant quiet wrap my head around why Thor does’nt move on the Y-axis. I hope someone can help me.

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

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

            String Xplane = "";
            String Yplane = "";
            // Write an action using System.out.println()
            // To debug: System.err.println("Debug messages...");
            if (lightX < initialTx){
                Xplane = "W";
            }
            else if (lightX > initialTx) {
                Xplane = "E";
            }
            else if (lightY < initialTy) {
                Yplane = "S";
            }
            else if (lightY > initialTy) {
                Yplane = "N";
                
            }
            // A single line providing the move to be made: N NE E SE S SW W or NW
            System.out.println(Xplane + Yplane);
        }
         

    }
}

The statement says:

Note that the coordinates (X and Y) start at the top left! This means the most top left cell has the coordinates “X=0,Y=0” and the most bottom right one has the coordinates “X=39,Y=17”.

So your code is moving Thor in the wrong direction in Yplane.

Also, note that you have to update Thor’s position manually, so that your code determines the required direction in later turns correctly.