Don't Panic - Episode 1 - Puzzle discussion

I am getting the same number of rounds with C++ and Python. Are you sure your code is not crashing or that you do issue a valid command ?

1 Like

Bonjour.
Jā€™ai un soucis avec le puzzle ā€œDonā€™t Panicā€.
Voila jā€™ai bien compris le principe pour rĆ©soudre ce puzzle mais je nā€™arrive pas Ć  utiliser et a me servir des ā€œconst elevatorFloor et elevatorPosā€ qui se trouve dans une boucle for.
Si quelquā€™un pourrait prendre un peu de son temps pour m 'aider ƧƠ serait vraiment cool.
Merci dā€™avance.

you need to store this input into the structure of your choice so youā€™re able to use it later, when you need to know the position of the elevator at floor n

I have some issues with Python 3 on this puzzle. Everytime I try to use elevator_floor or elevator_pos, the console output says that such variables do not exist. The other 8 variables (nb_floors, width, exit_floor, etc.) work fine

youā€™re trying to use the variable outside of the scope where it is defined (inside the loop). You must store the inputs in a variable defined outside of the first loop if you want to reuse it.

Thank you Thibaud for the answer. I understand the issue. I was doing what you have said, but I was trying to use those variables in test 1, where there is only one floor.

I canā€™t use the variable **elvator_pos**, it says that itā€™s undeclared i donā€™t know why :ā€™ā€™)

Because itĖ™s not declared in your code. :wink:

i just realized i canā€™t use a variable outside the loop it which it was declared in XD

In Python, you can. šŸ§Œ

Get trouble with validator 1 of episode 1. Canā€™t pass it when blocking the very first head-clone before 3rd step : this avoids cloning. Meanwhile, 3rd step in validator 1 leads to exit the floor on right side.
Any suggestion ?

Cool, it seems that the answer is in the text of the puzzleā€¦ :grin:
Have a look to comments posted on November 2017 !
Solution is there.

1 Like

Hey do you know why itā€™s not working?(sorry if my english is false)

#include <stdlib.h>

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

/**

  • Auto-generated code below aims at helping you parse
  • the standard input according to the problem statement.
    **/

int main()
{
// number of floors
int nb_floors;
// width of the area
int width;
// maximum number of rounds
int nb_rounds;
// floor on which the exit is found
int exit_floor;
// position of the exit on its floor
int exit_pos;
// number of generated clones
int nb_total_clones;
// ignore (always zero)
int nb_additional_elevators;
// number of elevators
int nb_elevators;

int elev_pos;
int elev_floor;
int table_posElev[20];
scanf("%d%d%d%d%d%d%d%d", &nb_floors, &width, &nb_rounds, &exit_floor, &exit_pos, &nb_total_clones, &nb_additional_elevators, &nb_elevators);
for (int i = 0; i < nb_elevators; i++) {
    // floor on which this elevator is found
    int elevator_floor;
    // position of the elevator on its floor
    int elevator_pos;
    scanf("%d%d", &elevator_floor, &elevator_pos);
    elev_pos = elevator_pos;    
    elev_floor = elevator_floor;
    table_posElev[i] = elev_pos; 
    }

// game loop
while (1) {
    // floor of the leading clone
    int clone_floor;
    // position of the leading clone on its floor
    int clone_pos;

    int elev_position = elev_pos;

    // direction of the leading clone: LEFT or RIGHT
    char direction[11];
    scanf("%d%d%s", &clone_floor, &clone_pos, direction);
    

    // Write an action using printf(). DON'T FORGET THE TRAILING \n
    // To debug: fprintf(stderr, "Debug messages...\n");

    if(clone_pos == width-1 || clone_pos == 0){
        printf("BLOCK\n");
    }
    else{
        printf("WAIT\n");
    }

    if(exit_floor > 7){
        if(clone_floor == 0){
            if(clone_pos == width-1 || clone_pos == 0){
                printf("BLOCK\n");
            }
            else{
                printf("WAIT\n");
            }
        }
        else{
            if(clone_pos > elev_position && strcmp(direction,"RIGHT") == 0){
                printf("BLOCK\n");
            }
            else if(clone_pos < elev_position && strcmp(direction,"LEFT") == 0){
                printf("BLOCK\n");
            }
            else{
                printf("WAIT\n");
            }

            if(clone_pos == width-1 || clone_pos == 0){
                printf("BLOCK\n");
            }
            else{
                printf("WAIT\n");
            }
        }
    }
}

return 0;

}

If the exit floor is not greater than 7: only your first if statement is executed, while your second batch of if statements is always ignored.
If the exit floor is greater than 7: both your first if statement and your second batch of if statements are executed (one after the other) in every single turn.
The logic is wrong in both scenarios.

thanks, now i make this and itā€™s also not working

if(clone_floor == nb_floors-1){
        if(clone_pos > exit_pos && strcmp(direction, "RIGHT") == 0){
            printf("BLOCK\n");
        }
        else if(clone_pos < exit_pos && strcmp(direction, "RIGHT") == 0){
            printf("BLOCK\n");
        }
        else{
            printf("WAIT\n");
        }
    }
    else{
        if(clone_pos > elev_pos && strcmp(direction,"RIGHT") == 0){
            printf("BLOCK\n");
        }
        else if(clone_pos < elev_pos && strcmp(direction,"LEFT") == 0){
            printf("BLOCK\n");
        }
        else{
            printf("WAIT\n");
        }
    }
  1. Check your directions.
  2. As your clones move up each floor (i.e. clone_floor changes), does your code update the value of elev_pos?

Have you resolve your problem ? Iā€™m facing the same issue.

You may click RESULTS then DETAILS to watch a replay of the validator which you fail to pass. Then you may figure out a way how to debug your code.

1 Like

Thanks . Iā€™have passed all the test exepte the U turn. But Iā€™v fix it now.

Hello,

In bash, I canā€™t get the elevatorFloor and elevatorPos variables out of the loop into another variable to use them in my conditions

Iā€™m a complete beginner, could someone help me?