Power Of Thor - Episode 1 - Puzzle discussion

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 ?

Your character is allowed to move in 8 directions (including diagonals), are you making use of that fact?

yep, i tested it with this: (python)

thorX = initialTX
if thorX == 15 :
    print 'SW'
else :
   print 'W'
   thorX = thorX - 1

Your character is also allowed to change direction during its course. :wink:

yeh I know, but when I use this code, at the end I have this result

Failure: Thor wandered off the path and died (invalid position).
Thor position = (1,18). Light position = (0,17). Energy = 15

He fail at one position to the light.

Well, apparently your program sends SW instead of W. Which means that he believes that thorX == 15 while actually thorX == 1. So, why is that happening…?

hey it works !!
but the thing is that I put the limit a 18, xD I rely don’t understand
thanks for your help :smiley:

The map height is 18, which means that Thor can go from thorY=0 to thorY=17. In your case, he was at (2,17), then tried to move SW, resulting in (1,18), and death.

for you and admins - please, change light position in 3rd test from 0,17 to 1,16 - and see how much people will have problems with it
limitations is not quite correct way to solve this puzzle, with correct algorithm you don’t have to check for limits

Dude you miss direction E

Hi guys. I am stuck in assigning an empty value for directionX and directionY
The tried the following
directionX = ‘’
directionX = None

but I still got the error message " Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found ‘None’"

Thank you

Your assignment works. The error message is not from the compiler. It’s from the program checking the output of your program.

Your program has to output one of the strings “N” … “NW”. You either assigned “None” to directionX and did output that string. Or you forgot to flush the output stream and did not output anything.

Kan a person help me