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 ?
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.
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ā¦
Have a look to comments posted on November 2017 !
Solution is there.
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");
}
}
- Check your directions.
- 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.
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?