Power Of Thor - Episode 1 - Puzzle discussion

Whoops! My first goto was geometry too. I should have thought harder about that decision when the topic for the problem was logic. But my solution has NO logic, just math.

yeah! I have it too… but I still guessing that is my mistake… did you fix it?

C++. When I pass all test cases and after resolving i get 25% and when I pass 3 TC i get 50%. According to this logic i shoul have 0 TC to get 100%. Moreover when i order to move south “Thor” moves north even when there are no move north command in code at all. Seriously what happens?!

I’m not surprised for the begining of your message, if your algorithm is wrong and use bad heuristics, there could be a lot of changes between tests from ide and test on submission.
But the second part, where you’re talking about wrong displacements, is weird. Can you send your code to coders[at]codingame[dot]com?
Thanks in advance

Hello,

Humm we have to update the thor position right ? Not read-it from the console ? The text problem mislead me…

2 Likes

A simple and relaxing coordinates problem, NICE!

...
if ((LX=TX) && (LY<TY))
{
    ...
}

EDIT: no full code please

error here ?

To verify if two integers are equal, you should use “==” operator.

Hey , it seeems there is a bug on the game becaus i did somthing Logic but it doesnt work by my side :

if((LX - TX) == (LY - TY)) System.out.println(“SE”);
else if((LX - TX) == (TY - LY)) System.out.println(“NE”);
else if((TX - LX) == (LY - TY)) System.out.println(“SW”);
else if((TX - LX) == (TY - LY)) System.out.println(“SE”);
else {

            if(TX < LX) System.out.println("E");
            else if(LX < TX) System.out.println("W");
            else if(TY < LY) System.out.println("S");
            else System.out.println("N");  
3 Likes

If (LX - TX) == (LY - TY) is true then (TX - LX) == (TY - LY) is true too because (LX - TX) == -(TX - LX) and same with Y. Basically, you can enter in only 2 of your 4 first conditions and you’ll always go SEor NE even when you should go towards respectively NW or SW (so the completely opposite direction).

Isn’t the description obscure, as it doesn’t specify which to move the charactore when one wants to decrement the x-coordinate of his location (East or West)? Of cource one submission can reveal which is which, but I think it’s better described in the sentence (or any of the sample input/output).

On a map, north is often (if not always) on top, so east is on the right, and west on the left.
So east is equivalent to x + 1
and west to x - 1
But i get your point. Maybe it should be added to the subject

I solved it without the need of updating Thor’s position, I guess was intentional by the devs

Hi There

I was solving this game and I think i found a bug
Here we have starting values:

Thor position = (31,4). Light position = (0,17). Energy = 44

To get to the energy we should go into SW direction and then when TY is equal to LY go to W direction

So according to XY coordinate rules:

I would imagine if we move to SW direction - then X and Y have to decrement, however Y coordinate is incrementing what we clearly see from the consol

Thor position = (31,4). Light position = (0,17). Energy = 44
Standard Output Stream:
SW
Thor position = (30,5). Light position = (0,17). Energy = 43
Standard Output Stream:
SW
Thor position = (29,6). Light position = (0,17). Energy = 42
Standard Output Stream:
SW
Thor position = (28,7). Light position = (0,17). Energy = 41
Standard Output Stream:
SW
//and so on....

It is mean that original start coordinates of the “Thor” [31,4] and the “Light” [0:17] cannot be right if light located bellow Thor on Y coordinates. And Y cant go [++] each time Thor go down, it must go [–]

I did solve it, however original concept messed up and confusing people!

2 Likes

This isn’t a bug.

If you look at the problem images, the origin is in the top left corner, and axes are clearly showing that Y has to increase to go south.

To say it another way: the only rules applying are the puzzle ones. Conventions like Y increasing = going north doesn’t apply if not clearly stated.

3 Likes

Like @NewboO said: nobody said that the origin is in the left-down corner. More than often, and in this case too, the origin is on the top-left corner.

But stll, you just have to find out about it, that the main exercice of this problem.

1 Like

The image instructions for this are incorrect, stating Thor’s final position as (3, 6). On Turn 2, Thor moves south from (3, 7) and should arrive at position (3, 8), i.e. at the position of the Light.

Hy!

I need a help. I have the code below that doesn’t work in testcase 3 and I don’t know why. I hope somebody can explain me why.

import java.util.*;

import java.io.;
import java.math.
;

/**

  • Auto-generated code below aims at helping you parse

  • the standard input according to the problem statement.
    **/
    class Player {

    public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int LX = in.nextInt(); // the X position of the light of power
    int LY = in.nextInt(); // the Y position of the light of power
    int TX = in.nextInt(); // Thor’s starting X position
    int TY = in.nextInt(); // Thor’s starting Y position

     // game loop
     while (true) {
         int E = in.nextInt(); // The level of Thor's remaining energy, representing the number of moves he can still make.
    
         // Write an action using System.out.println()
         // To debug: System.err.println("Debug messages...");
    
         int dx = direction(LX - TX);
         int dy = direction(LY - TY);
         
         move(verticalMovement(dy) + horizontalMovement(dx));
    
         // System.out.println("SE"); // A single line providing the move to be made: N NE E SE S SW W or NW
     }
    

    }

    private static void move(String direction) {
    System.out.println(direction);
    }

    private static String verticalMovement(int dy) {
    switch (dy) {
    case -1: return “N”;
    case 0: return “”;
    case 1: return “S”;
    default: return “”;
    }
    }

    private static String horizontalMovement(int dx) {
    switch (dx) {
    case -1: return “W”;
    case 0: return “”;
    case 1: return “E”;
    default: return “”;
    }
    }

    private static int direction(int diff) {
    return (int) Math.signum(diff);
    }

}

HI, sorry but I don’t speak english…

in c++ i write this
if ((LX!=TX) && (LY!=TY))
{
[BLOCK A]
}
else
{…BLOCK B

my problem is…
when TY became = at LY the IF execute the BLOCK A not the else (BLOCK B)

sorry for the english, someone can help me?

By the looks of it my post will be a drop in the bucket, but any way.

In case you does not want to branch a lot and willing to crack out some vector (or complex) algebra you can simplify this to a minimisation, as follows.

d = T - L
T += min( cos⁻¹( d · m / ( | d |·| m | )) : m in M ),

where M = { (0,1), (1,1), (1,0), …, (-1,0), (-1,1) } and T=(TX, TY), L=(LX, LY).

Note: if you use complex numbers you should do something like:

T += min( cos⁻¹( re(d · m̅) / ( |d|·|m| ) ) : m in M ),

where m̅ is the notation of conjugation and re(m) is the real part of the complex number.

Of course you might need a “dictionary” for M to project it into output set, namely {‘S’,‘SE’,‘E’,…,‘W’,‘SW’}.

If you’re wonder this minimises the angle of move and destination.