Power Of Thor - Episode 1 - Puzzle discussion


#566

I have to say, I fully coded a student demo learning by myself and I have hard times resolving this first test.
Quitting the introduction code, you are dropped without indication for the next puzzle or what. This is a bit harsh when you’re not learning code in classroom.
Thanks anyway for providing such a cool space to learn.


#567

It sounds like maybe you didn’t see the problem statement? It’s sometimes hard to notice on certain screen sizes (I didn’t notice it for the first few puzzles, myself) but if you hover the mouse over the graphics section and scroll down, you’ll get a description of what you’re supposed to do, complete with a line-by-line explanation of what the inputs mean and what format the output is supposed to be given in.


#568

Thank you for your answer !
Yes I’ve seen the indications below and achieved the first and second tests.
I don’t know, maybe it’s because I’m coming from Unity, but I don’t understand how things work.
Maybe I could send you my code if you have some time for that ?


#571

can someone help me on solving the game. ::sweat_smile:


#572

There is help in the window. :wink:


#573

thanks:slight_smile:


#574

can someone explain to me why this cause Thor to go south even if he’s on the same Y as the light ?
if(lightY-initialTY>0&&lightY-initialTY!=0) {
printf(“S\n”);


#575

most probably because Thor is initially North of the Light.


#576

Hey

I couldn’t figure out if there is a way to get Thor’s X,Y coords during the loop.
What am I missing?

(language JS)

Thanks!


#577

You have to manage them by yourself.


#578

Hello! I am doing java. Can you help me with second level
“please”


#579

Hello people,
I’m using PHP and used a switch to pass these test cases.
It is working fine for (nearly) all test cases, global idea is :
switch ($Y)
{
case ($Y < $lightY):
echo(“S”);
$Y++;
break;
case ($Y > $lightY): //move N
echo(“N”);
etc (and same for $X, and a final echo("\n") to …

My problem is at the start of the last case : initial value for X and Y are 0 : it seems that my compares don’t work when $Y and $X are ‘0’.
If I initialize their value to ‘1’ : it works great, but not when initialized at ‘0’.

I can customize the code to pass this specific test case, but I don’t understand why I have this behaviour.

Even with a if ($Y == 0), I don’t enter this condition

Any idea about my mistake (is it specific to PHP, or a bug) ?
Many thanks,
Pierre


#580

Let’s imagine that, at a given time, Y = 5 and lightY = 3. You code will then be equivalent to:

switch (5)
{
    case (0): // 5 < 3 is false here.
        echo("S");
        $Y++;
        break;
    case (1):  // 5 > 3 is true here.
        echo("N");
        // ...
    // ...
}

As you can see, it doesn’t make any sense at all. Getting rid of this strange switch and converting your cases into if/else is probably what you want.


#581

Hi Aries1,

Thank you for your answer.
I don’t clearly understand your point : it is working very fine for cases1, 2 ,3 and 4 (for this one, only if I start with values of X,Y > 0)

For test case 4, I have values :
X = 0
Y = 0
lightX = 36
lightY = 17
For $Y = 1 and $lightY=17 :

switch ($Y)
{
case ($Y < $lightY): //move S --> 0<17, should be TRUE, right ?
echo(“S”);
$Y++;
break;
case ($Y > $lightY): //move N
echo(“N”);
$Y–;
break;
}
[…similar switch for $X : 0<36, I should have E]

echo("\n");

And I had \n to the echo -> I’m expecting “SE\n” for the 17 first steps.

But…
when beginning with X=0, Y=0 : tests are going crazy and I get NW instead of SE… :frowning:
I tried same code with X=1, Y=1 : everything is working fine (SE etc)

If someone know what’s happening ?
As I said, I’m in PHP : I thought about a type issue, but it doesn’t seem to be that.

Many thanks,
Pierre


#582
  1. You can perfectly “solve” the first test cases using a broken algorithm.

  2. You should take a more careful look at a “switch” documentation (http://www.lephpfacile.com/manuel-php/control-structures.switch.php per instance and in french because lapin compris).

Basically, the following statement:

switch (x)
{
    case (v1):
        // ...
        break;
    case (v2):
        // ...
        break;
    // ...
}

translates into:

considering the value of "x",
    if it has value "v1":
        // ...
        break;
    if it has value "v2":
        // ...
        break;

As you can see, it is mostly like a “if”, at least at the code level.

The error you make when writing your cases is that you put a whole condition into them, not understanding they will be first evaluated to a value before being compared with.

Per instance, when you write

case ($Y < $lightY): ...

I doesn’t translate to

if (Y < lightY) then ...

But to

if (Y == (Y < lightY)) then ...

More elaborate languages / compilers will notify you that comparing a integer with a boolean is suspicious, but… PHP.


#583

Thank you again Aries,

I wanted to use switch instead of if, but I understand it will be difficult with the logic I wanted to use.

:smile: :smile:


#584

how do you update the direction using c++?


#585

You don’t update the direction. You have to update Thor’s coordinates (depending on the move) and recalculate the direction in a loop.

...
cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();

int tx=initialTX; int ty=initialTY;
while(tx != lightX || ty != lightY) {
  ...
  if (...) {
    cout << "N" << endl;
    ty--;
  }
  ...
}

#586

Hi, do you know why the code cannot work with char but only with strings ? I hope you see what I mean because it seems like we’re not allowed to post our code here.
Thanks for your help :slight_smile:


#587

please post small snippet of code, this is not against the rules