Power Of Thor - Episode 1 - Puzzle discussion

Could you please explain a bit more about what you’re trying to do, like, how you intend to move Thor? I’m afraid I can’t understand your message.

If you want to reduce the number of turns to move Thor, you should move Thor in a diagonal direction as many times as needed. For example, if you move Thor N and then E, that’ll take two turns, while it takes just one turn to move Thor NE directly.

it’s more, i’m looking to make the code smaller? like, after i figured out the X Y axis idea, to go N +/- 1 depending on initial_ty. I wanted to see if i can condense the script for the code? is there any way instead of doing +/- = 1 on the X/Y axis, without having to utilize numbers? or is the most efficient way of reaching the destination just +/- 1?

Once you’ve got the initial data, you can already plan ahead what moves to do without referring to subsequent data. Maybe that’ll help you condense the script in some way? But even then, you still have to “utilize numbers” for at least one turn.

right. i feel like doing if thor_x > light_x:
direction_x = “W”
thor_x -= 1

isn’t good enough in a sense? to have one string per direction feels like it needs to be made more efficient so i’m trying to figure out how i can create a string that makes Thor move without as much lines of code.

I genuinely feel too dumb right now. Cannot get the second challenge of getting Thor to do down. Any pointers? Trying to learn python

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.

You’ll also find some Python learning resources here.

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