Power Of Thor - Episode 1 - Puzzle discussion

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);

What am I doing wrong guys?

NO FULL CODE

Beside posting your code, being confused by value bounds:

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”.

@krazyking008 : What happens to your D variable when TY equal LY ?

I wonder how is it possible to solve this puzzle in OCaml.
Although I am new to OCaml, I tried very hard.

I tried to delete the default while true game loop and use a recursive function instead. This way variables don’t need to be mutated, because they are passed as function parameters. The function would be return unit. But I could not produce any output, regardless I wrote the print statement before the recursive call. Maybe I made a mistake mixing functional and imperative constructs.

My other idea was to keep the default game loop but use state monad to store and update the position of Thor. Because I am new to OCaml I gave up this aproach.

Please help. In theory how can it be solved using a functional language? What do you think my mistake was?

Hi y’all. I’m very confused here. I’ve done a few tutorial courses on C# and found this site to learn more. But all the instructions are extremely abstract and I don’t understand anything. Am I supposed to have a Computer Science degree to do any of this?

Here is a functional template. You need to fill in the [...].

(* Game loop. Parameters are:
     lightx, lighty: coordinates for light
     thorx, thory  : coordinates for Thor
*)
let rec thor_run lightx lighty thorx thory =
    (* get next line of input *)
    let remainingturns = int_of_string (input_line stdin) in
    (* compute Thor's new position *)
    let (new_thorx, new_thory) = [...] in
    [...]
    (* print instructions *)
    print_endline [...];
    (* go for next round *)
    thor_run lightx lighty new_thorx new_thory
;;

(* get first line of input, and launch game loop *)
Scanf.sscanf (input_line stdin) "%d %d %d %d" thor_run;;
2 Likes

Thanks a lot Plopx. Your skeleton was very similar to my first attempt code, but bug-free :smile:
100%

hey guys I have a problem with the 3rd --> easy angle , I can’t touch the light without touching the limit :confused: it’s that a bug ?