Shadows of the Knight - Episode 1 - Puzzle discussion

sry I have a too overcomplicated way of thinking. no idea how to fix that
my IQ is just 115.

Struggle generally with grasping algorithms, that’s why I try to learn and this one was insanely frustrating to me

Hi Samsam333,

Try to use : y0 = y0 - math.ceil((y0-uh)/2)
instead of y0 = y0 - ((y0-uh)//2)
because this division // is not relevant for this exercice( because of around).

Hi everyone ^^

I’m a bit stuck with my code (C#) can you help me please ? ><

The code is working but is not optimize, some time he need too much jump to find the target point

Here is the core of my code:

Code
 while (true)
        {
            string bombDir = Console.ReadLine();

            foreach(var letters in bombDir)
            {
                switch(letters)
                {
                    case 'U':
                        Hmax = Y0;
                        Y0 -= (Y0 - Hmin)/2;
                    break;

                    case 'R':
                        Wmin = X0;
                        X0 += (Wmax - X0)/2;
                    break;

                    case 'D':
                        Hmin = Y0;
                        Y0 += (Hmax - Y0)/2;
                    break;

                    case 'L':
                        Wmax = X0;
                        X0 -= (X0 - Wmin)/2;
                    break;

                    default:
                    break;
                }
            }

            // the location of the next window Batman should jump to.
            Console.WriteLine($"{X0} {Y0}");
        }

And if possible not a direct solution but more some advice :wink:

Hi maldeirra,
When I looked at the code, I saw two things you could do to make it work better:

  1. Since the bomb is not at the window where Batman is standing - as you are receiving a direction - it is better to exclude it, by putting Y0 + 1 or Y0 - 1 or H0 + 1 or H0 - 1 according to the direction.

  2. Instead of modifying the X0 and the Y0 in the switch statements, you can remove them and put a more generalized modification (outside the switch statement), making it much easier to understand, which will look something like this:
    X0 = Wmin + (Wmax - Wmin)/2;
    Y0 = Hmin + (Hmax - Hmin)/2;

These two modifications are enough for the code to get a 100%. Hope it helped!

3 Likes

Thanks for the help !

It definitevely help me to remove the X0 and Y0 from the switch, I got my 100%. ^^
I search for your 1) but i didn’t need it for the final solution. :thinking:

I think Groovy test environment is broken. In GUI mode it sometimes fails with the message:
Timeout: your program did not provide an input in due time.

When I run that test again everything is ok.

When I submit my solution some tests are broken. The same code passes all GUI tests, but then 50% fails. I submit my code again and then 25% fails. And I submit is again and then 20% fails.

I think code is good. Similar code works in Python, Java, JavaScript, C++ and other languages, so I think something is wrong with Groovy test environment.

Yes, Groovy issue is not unique to this puzzle; other puzzles have the same issue.

1 Like

last test “not there” is time out error seems the last wall is so large, using Golang but the creation []int slice and fill it with value 0:9999 is taking so long , is any way in golang to filll []int slice quick not using append function?

I don’t think you need to create []int slice for this puzzle. You just need to keep track of the minimum and maximum of possible x and y values and reduce the search range at each step.

I have exactly the same with python. At first I thought my code was too slow so i timed it using :
from timeit import default_timer as timer
and the timing the while loop
but my average time is around 0.03ms
and my print are correct . I don’t understand

Do you mean you receive the warning for not reading all the inputs? If so, it may be either you output something before you have read all the inputs, OR you output more than once in a turn.

that was the second choice . thanks for the reply

Hi All ,

If anyone can help in understanding the the output 1 for this problem , i.e for UR , (2,5) ; how the output is 5 4 .

Thank you for assisting !

Hi,
if i right understand the point ur asking to,
you true, i think it’s a mistake

we start on 2,5
we receive UR as order
the Width max is 9 (RIGHT)
(9-2)/2 => we have to add 3 (7/2 return 3 cause is an int)
the 2 becomes 5

the Height min is 0 (UP)
5/2=2 (again, cause the int value)
5-2 = 3
the 5 becomes 3

the tests when you resolve the cases are ok

Hi, I have a question.
Although I have solved a puzzle, I still want to learn from other better solutions. So where can I see other solutions?
Thanks!

1 Like

On the front page of the puzzle https://www.codingame.com/training/medium/shadows-of-the-knight-episode-1 you can find others’ solutions. You can view them if you have solved the puzzle in the same programming language.

1 Like

Oh!! Thank you. It helps me a lot

Hello,
In my code, I have an error in the test 2 : less jumps.
For the other tests it’s OK.
Can you help me?
Thanks

You need to describe what your code currently does. Remember not to post any full code here, though.

I am using C language. I can not read the direction information with the below code. What is wrong with the if(bomb_dir == “DR”)

    while (1) {
        // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
        char bomb_dir[4];
        scanf("%s", bomb_dir);
        int x,y;
        // Write an action using printf(). DON'T FORGET THE TRAILING \n
        // To debug: fprintf(stderr, "Debug messages...\n");
        if(bomb_dir == "DR")
        {
            x=3;
            y=3;
        }

        // the location of the next window Batman should jump to.
        printf("%d %d\n",x,y);
    }```