[Community Puzzle] Detective Pikaptcha EP2

Thank you, I finally managed to understand it but didn’t know the flush function, i’ll remember it :slight_smile:

Hello there,

I’m a little bit confused, i don’t get the final condition that let you make a conclusion about the end of travel and sout the solution.
I mean the 1st test pass easy, but it can’t be :

  • you pass through the same initial point : test 2 will fail
  • you have to pass at least once on every valid space : test 3 will fail

Do you have any tips about an end condition for the loop ?

Thx in advance

loop {
when current(x,y) equals starting (x,y)
break;
}

thx for answering, I don’t really understand your answer because i think that the test 2 will fail because you have to pass by the initial point twice (at the start and during the transition between left and right part of the “room”). Isn’t it ?

In Test 2 you should not pass the starting pt twice.
Once finished a chamber, arrived at the starting pt, STOP - because the rule says so.
Report counting.to finish.

Thank you, i will retry.

edit : it works well, the reason it doesn’t work the first time is i swap coordinates X and Y by mistake. So ofc he would never reach the “initial point” where X and Y aren’t the same at start (contrary to the 1st test).

  • a tip for dodging infinite loop with a trap pikachu (test 3).

Thx a lot, have a good day

I have a weird error in my code. I read the input and save it to a variable called grid. After I initialise each cell of the grid I print it to make sure it is correct and indeed it is. After I have initialised all cells in the grid I print it again However, this time some random cells are printed as null while I have not changed anything between the two prints. Here is my code and my console output:

private static char side;
    private static int[] position = new int[2];
    private static int[] initialPosition = new int[2];
    private static int[] direction = new int[2];
    private static char face = '~';
    private static String[][] grid;
    private static int width = 0;
    private static int height = 0;
    private static boolean finished = false;

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        width = in.nextInt();
        height = in.nextInt();
        grid = new String[height][width];
        for (int i = 0; i < height; i++) {
            String line = in.next();
            for (char c : line.toCharArray()) {
                int indx = line.indexOf(c);
                switch (c) {
                    case '>' :
                    case 'v' :
                    case '<' :
                    case '^' : {
                        face = c;
                        initialPosition[0] = i;
                        initialPosition[1] = indx;
                        position[0] = i;
                        position[1] = indx;
                        grid[position[0]][position[1]] = "0";
                        break;
                    }
                    default : {
                        grid[i][indx] = "" + c;
                        System.err.print(grid[i][indx]);
                    }
                }
            }
            System.err.println();
        }
        System.err.println();
        for (int i = 0; i < height ; i++) {
            for (int j = 0; j < width; j++) {
                System.err.print(grid[i][j]);   
            }
            System.err.println();
        }
.....(rest of code)
}

Standard Error Stream:

000#

#0#00

00#0#

00nullnull#

#0nullnullnull

0null#nullnull
int indx = line.indexOf(c);

This won’t give the correct index if there are multiple instances of c on one line (eg it’ll always be 0 for the string “####”).

1 Like

Thank you very much! You are right, I was initially only using that for the special starting character of which there was always one.

Hello, I can’t understand the difference between “Two Chambers” from tests and validations. In both cases, it looks like the initial direction is TOP and Right-handed, but it runs in different ways (Left and Right).
Tell me where I wrong, please?

Between the test case and the validator, the mazes do have different sizes. Starting coordinates are different. Directions are different. Not a surprise they run in different ways.

It is easy to obtain the map of the test case: print the data in debug message as you read them. The map, direction and size, all will be in console.

I totally understood your thoughts, but I can’t figure out what the logic of initial step?
I’m asking this because I did a lot of tests (including hardcoded initial step), so now I know that “Two Chambers” have the same direction and hand for tests and validation. The positions same too:
###
0^0
###

So, in both cases I should go in the same direction. When I go to the left in that situation then validation is failed, otherwise test failed.
So, How I should understand where I need to go?

I guess what you saw were the test case data in console and the test case animation when it is running.The validator data is hidden, and no animation is based on it.

btw, have you printed out the input data by debug message in console? Your few lines of pattern does not look like anything I can recognize in the existing test cases.

As expected - I have found my mistake in initial Direction Recognition block :grin:
Btw, Thanks for your responses.

Seems that this puzzle is more middle lvl than easy lvl, isn’t ?

I must have done something stupid, I wrote more code than for other ‘easy’ puzzles… ^^

Anyway, I’m happy of my implementation with itertools to cycle through the directions and a recursive function :slight_smile:

Funny Pikatcha !

Ps: I had to increase the recursion limit

I didn’t solve this one with a recursive function.

All tests are correct without cheating but when submitting there are 2 errors 5 and 6.
The system gives no clue if it is a timing resource or a logic error.
so i’am stuck.
very unsatisfactory.
btw I use java.

I am not sure if I get the logic right. Why can’t this a possible solution for “A small chamber” test?
1222#
#0#31
00#1#

Does it mean he has to visit every cell at least once? I don’t get what “follow a wall” means. Can someone help?

“visit every cell at least once” - absolutely not the requirement.
But when Pikaptcha is coming back, from right to left and at the cell indicated with bracket as below…

1 2 (2) 2 #
# 0  #  3 1

He is touching, following the Left wall. He should follow the wall to turn left, going down, and then come up again.

1 Like