Power Of Thor - Episode 1 - Puzzle discussion


Thanks for answering.
If I change this :
string verticaldirection="";
string horizontaldirection="";
to this:
char verticaldirection=’’;
char horizontaldirection=’’;

and then do for example:

It does not work, I have to use string and verticaldirection=“S”;

Weird no ?


char verticaldirection=''

what language is this? In most languages this is invalid and won’t compile or will throw an error at runtime (because there is no “empty” char, char is always one symbol while a string can be zero or more symbols )


Oh ok, that must be why then. The language is C++. Thanks for the info, this is really appreciated :slight_smile:


Hi there,

I just wondered why I couldn’t set $directionX without value just like $directionX; Why it must be set with null value like $directionX = ‘’;



Why with the VB.NET language, the solution doesn’t work for the points 3 and 4 (the easy angle and the optimal angle)?
What’s wrong in my script?
Sub Main ()

    Dim inputs as String()
    Dim lightX as Integer ' the X position of the light of power
    Dim lightY as Integer ' the Y position of the light of power
    Dim initialTX as Integer ' Thor's starting X position
    Dim initialTY as Integer ' Thor's starting Y position
    inputs = Console.ReadLine().Split(" ")
    lightX = inputs(0)
    lightY = inputs(1)
    initialTX = inputs(2)
    initialTY = inputs(3)
   dim  thorx as integer = initialTX
   dim   thory  as integer = initialTY
    Dim directionx as String =""
    Dim directiony as String = ""
    ' game loop
    While True
        Dim remainingTurns as Integer
        remainingTurns = Console.ReadLine() ' The remaining amount of turns Thor can move. Do not remove this line.
        if thorx > lightx then 
           directionx = "W"
           thorx = thorx - 1
        else if thorx < lightx then
            directionx= "E"
        thorx= thorx + 1
        end if
        If thory >  lighty then 
            directiony = "N"
        thory= thory - 1
        else if  thory < lighty then
            directiony = "S"
        thory = thory + 1
        end if
    Console.WriteLine(directiony & directionx)

    End While
End Sub

End Module


Because directionX/Y variables defines outside the loop and you’re not clean they after output, so they preserve their value between iterations, whereas they shouldn’t do that


Hi. I wrote a solution in C#.
Everything passes except the third case after submitting.
I innately look for my fault when things go wrong, however…

This is a screen shot from the failing test. It kinda looks like I’ve reached the point, right?
Thor continues going East after this until reaching the edge of the screen, which isn’t logically possible from the code I’ve written.
Has anyone else encountered this error on the 3rd submission check for C# ?

        if (LX>TX) {
            if (LY==TY) {s="E"; TX++;};
            if (LY>TY) {s="SE";TX++;TY++;};
            if (LY<TY) {s="NE";TX++;TY--;};
        if (LX<TX) {
            if (LY<TY) {s="NW"; TX--; TY--;}; 
            if (LY>TY) {s="SW"; TX--; TY++; }; 
            if (LY==TY) {s="W";TX--;};
        if (LX==TX) {
            if (LY>TY) {s="S"; TY++;};
            if (LY<TY) {s="N";TY--;};

Using this code I have passed three test, but test easy angle didn’t passed (
When Thor went to the bottom of the field, he didn’t increse his coordinates by 17…
what is wrong?

Standard Output Stream:
Game information:
Thor’s moving…
Thor position = (19,16). Light position = (0,17). Energy = 32
Standard Output Stream:
Game information:
Thor’s moving…
Thor position = (18,16). Light position = (0,17). Energy = 31


It is a good example to illustrate how a functional code would be both safer and easier to read than an imperative one. Keeping with the latter, I think you should quickly understand why you need some “else” in your code once you have renamed TX and TY with their true names:


If, out of curiosity, you want to grasp how a functional code would has been safer to design here, simply force yourself to only use “final” / “const” (or whatever could make them imutable) variables.

Note: you don’t need to put a semicolon after a closing brace.


It’s likely you’re hitting a scenario where you’re doing 2 operations in the same pass. For instance, if LX == TX + 1 and LY == TY, then you’ll fall into the LX == TX check a few lines down.


Hi guys !
I’m a beginner and i don’t understand my mistake on Thor.
I wrote in Python a while : while light_x != Thor_X and light_y !=Thor_Y :

 and then i wrote 8 if, one for each direction. I saw that it is not the easiest way described in the pseudo code but it should still work, right ?


8 ifs can work, but you need to make sure you only execute one of them per loop (see the post above yours).

There are simpler ways, too. What about just checking North vs South, then East vs West?


hi I am kwebblecop how do I play this game?


Have you read the statement?
You have a help in the statement too.


I didn’t realise that this was about conditions, so I solved the general problem of executing the optimal move on an open 2D field.
The solution uses no conditions at all, it uses trigonometry and rounding to find the correct index in a list of predefined Move objects, and executes the found move, summing the result with the current position to update it.

The disadvantage:

  • Program is way more complex to write
  • Program is unreadable, since it consist of only one line that does almost everything.

The advantage:

  • Change the movement system to a hex or triangle grid, and my program will still work after you change the list of possible moves to reflect the new reality.


I’m programming in C. Can anyone help explain to me why my variables char *directionX and char *directionY only work as pointers?


maybe they are zero-terminated strings? also you should have enough space in output buffer to concatenate strings if moving diagonally


very new to programing and I’m a little stuck at 50% success. I’m not sure why its stopping the code from the next step saying its out of parameters the angle tests wont pass
(don’t know how to put code on here to show you)

basically i put if else statements as parameters

if light_y != initial_ty: #does he need to move up or down or none (north or south or none)
        if light_y > initial_ty:
            y = "S"
            y = "N"
        y = ""

and the same for the x axis then printing direction which is defined as y+x

any tips on what im doing wrong as to why it wont work for the angles thank you


Do you update Thor’s coordinates?


… i guess not…wow right in front of my face.
thanks =)