Power Of Thor - Episode 1 - Puzzle discussion

I can’t solve the whole thing but one!!!

like I can only solve one!!!

If you look to the left of the puzzle statement on https://www.codingame.com/ide/puzzle/power-of-thor-episode-1, you’ll find a HINTS button. Those hints may help you get started.

Also note that your code should be general enough to solve all the test cases.

#include
#include
#include
#include

using namespace std;

/**

  • Solve this puzzle by writing the shortest code.
  • Whitespaces (spaces, new lines, tabs…) are counted in the total amount of chars.
  • These comments should be burnt after reading!
    **/

int main()
{
int lx; // the X position of the light of power
int ly; // the Y position of the light of power
int tx; // Thor’s starting X position
int ty; // Thor’s starting Y position
cin >> lx >> ly >> tx >> ty; cin.ignore();

int tX;
int tY;
tX = initialTX;
tY = initialTY;
string dir;
// game loop
while (1) {
    int remaining_turns; // The level of Thor's remaining energy, representing the number of moves he can still make.
    cin >> remainingturns; cin.ignore();
    if       ((tX > lightX && (tY > lightY)) {  tX -= 1; tY -= 1; dir = "NW"; } 
    else if  ((tX > lightX && (tY < lightY)) {  tX -= 1; tY += 1; dir = "SW"; }  
    else if  ((tX < lightX && (tY < lightY)) {  tX += 1; tY += 1; dir = "SE"; } 
    else if  ((tX < lightX && (tY > lightY)) {  tX += 1; tY -= 1; dir = "NE"; } 
    else if  (tX > lightX) { tX -= 1; dir = "W"; } 
    else if  (tX < lightX) { tX += 1; dir = "E"; }
    else if  (tY > lightY) { tY -= 1; dir = "N"; } 
    else if  (tY < lightY) { tY += 1; dir = "S"; } 
    // Write an action using cout. DON'T FORGET THE "<< endl"
    // To debug: cerr << "Debug messages..." << endl;


    // A single line providing the move to be made: N NE E SE S SW W or NW
    cout << dir << endl;
}

}

Is this a question or a solution?

a question for a solution

I’ll wait even if it costs my life!

can I be your friend?

Please stop spamming the forum. Study the error messages in the console after you run your code, and then try to fix the bugs accordingly.

i wrote this code but it is not working in c and i am only a 9th grader so please teach this to me i dont understand nothing
if(TY< LY) {printf(“E”);}
else if(LX < TX) {printf(“N”);}
else if(TY < LY) {printf(“S”);}
else {printf(“SE”);}
please tell me what is wrong
btw i wrote TY, LY, LX and LX because i changed the variables

You have to print a newline every time after you output the direction for a round.

Also, your code has to update the positions of Thor if it does not do so at the moment.

If you look to the left of the puzzle statement on https://www.codingame.com/ide/puzzle/power-of-thor-episode-1, you’ll find a HINTS button. More hints are available there.

I have a question:

Why does the following code fail ?

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

    # Write an action using print
    # To debug: print("Debug messages...", file=sys.stderr, flush=True)
    dir = ""
    if light_y != initial_ty :
        if light_y-initial_ty > 0 :
            dir = dir + "S"
        elif  light_y-initial_ty < 0 :
            dir = dir + "N"
    else: 
        dir=""
    if light_x != initial_tx :
        if light_x-initial_tx > 0 :
            dir = dir + "E"
        elif light_x-initial_tx < 0 :
            dir = dir + "W"
    # A single line providing the move to be made: N NE E SE S SW W or NW
    print(dir)

This fails for an angle but by my understanding when the x or y coordinate becomes same thor should move in one direction like E or N and not SW or SE .

Sorry if this is stupid

You don’t seem to update Thor’s coordinates.

Ah i got it
Thanks man
sorry for the dumb question