Power Of Thor - Episode 1 - Puzzle discussion

@tod_lazarov, @Samarlynn: As it seems there’s clearly something wrong happening somewhere else in your code (because what both of you showed on the logic is correct), you can send me your code in private message if you like. It’ll be easier to help you efficiently so you don’t stay blocked on this for days :slight_smile:

Could the ‘bug’ be language specific…

It’s definitely not working in Ruby, I’ve triple checked my code, and it “should not” be doing what it is doing…

If you have this issue, you probably missed the fact that going down/south means increasing Y coordinate from an origin in the top left/north west. I recently validated it with 19 out of the 23 available languages, including Ruby, so there’s no language specific bug as far as I know.

Hello, I’m just beginning learn JavaScript recently and in this game I’m trying with many ways but I get this message in the console output :

" Timeout: your program did not provide an input in due time. Earth was destroyed!
Thor position = (5,4). Light position = (31,4). Energy = 100 " …

I need to know what’s the reason and how can I fix it ?

Kind Regards …

Its probably an Infinite loop.
Try to debug it line by line if you have and IDE. :slight_smile:

Timeout basically means that your program took too long to produce the output.

okay I will try it, thanks a lot.

what’s meant by IDE ?

IDE means integrated development environment and is meant to be a professional tool to develop highly maintainable and debuggable apps for the modern world :thumbsup:

what is the remainingTurns for? Is that the energy? and how to assign value to directionX,Y string?

remaining turns is the amount of turns before you fail - and if your algorithm is good you finish the task long before you run out of turns, so you may not take this into account
direction x and y strings is where you read from, to output you must introduce your own variable and print it to standard output, or print string directly without asigning it anywhere

1 Like

Tks! So that means I don’t need to do anything about the remainingTurns? I just forgot the syntax of assigning value to strings.

How do I update the thorX and thorY variables in javascript?


thorX++
thorX–
thorY++
thorY–

This is common in computer graphics. Origin is usually in the top left corner, and Y increases as you move down. It’s not just codingame. I’ve personally never worked with a graphics library or game engine that wasn’t this case by default.

In C I can’t seem to figure out how to get the ouput to work. I’ve tried printing my 2 char’s with

printf("%c%c\n", directionY, directionX)

And then my error looks like this:

Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found 'E'

EDIT: both directionY and directionX are initialized to ‘\0’. So I don’t understand how my output can be ‘E’ and then somehow be illegal.

The strange thing is that for diagonal movements this code works, it’s as soon as there is a horizontal or vertical movement that it crashes.

I’m really not familiar with C, but I’ve looked at many posts on SO for a solid answer. Unfortunately I can’t seem to figure out how to make an output that works.

I’ve tried creating a char string, but I can’t seem to figure out how to concatenate directionX and directionY together. At least not in a way that seems work for this challenge.

I’ve solved this challenge in C++, C#, Java, JavaScript, Bash, Python, and Clojure. I think I just don’t understand the semantics of C. Any help or at least a pointer in the right direction would be appreciated so much!

2 Likes
    char s[1];
    s[0] = 0;
    strcat(s, "N");
    printf(s);
    printf("\n");

trying to solve it in F#. i’m using a mutable variable to try and store thor’s new position outside of the scope of the game loop, but it doesn’t seem to update. any ideas?

1 Like

How can i do this i c++:

Update the thorX and thorY variables depending on the chosen directions (+1 or -1).

??

OK, i figured it out:

thorX--;
thorX++;
thorY--;
thorY++;

EDIT: Code simplified, cause too close to giving solution 
We often say “no full code”, this is mainly to not spoil the funny stuff to others. Here you gave almost everything to have a valid solution, care about it next time :slight_smile:

I need help

NO FULL CODE

Idk what to do anymore

I believe people will more tend to help you if you’re not just like “I do not read what has been said, I just post my code and ask for help”. That’s not respectful.
The message just above you was edited with a bold message. Same goes for yours.

Try to explain your problem, tell us the language you use, and eventually give some example of your code that is not doing what you expect it to do.
From what I saw of your code, when you launch a test there should be some red error messages in the output. In order to solve any game, your code must compile.

2 Likes

Any Idea why mine fails for 3rd and 4th…

if(TY > LY){
D = “N”;
TY–;
} else if(TY < LY){
D = “S”;
TY++;
}
if(TX > LX){
D += “W”;
TX–;
} else if(TX < LX){
D += “E”;
TX++;
}
Console.WriteLine(D);