Don't Panic - Episode 1 - Puzzle discussion

Which frame are you talking about?

I would suggest you to print all the variables which the if-condition contains, right before the if-block. This way you will see better why that condition passes or fails (and hence why the code within that block is executed or not).

On frame 61 the clone goes up a level. It goes into the BLOCK if as it is printing “block 4” but the program somehow understands a WAIT, as seen in the previous comment. There it the prints you mentioned showing that it does indeed go into the BLOCK section.

As the BLOCK gets ignored, it keeps moving until ~5 frames later when the BLOCK finally gets catched or something and stops.

A few points to note:

(1)
Remember that the code is always executed as how it is written. It won’t do more, it won’t do less. So, your program outputs “WAIT” or “BLOCK” based on how your code is written.

On CodinGame, the game engine receives the output from your code and update the next game turn accordingly. The game engine won’t execute a “WAIT” if you output a “BLOCK”.

If your debug shows “BLOCK” but your output shows “WAIT”, that means you have messed up your output somewhere.

(2)
I notice the first anomaly in your replay is during frames 36 to 39. A clone should have been blocked earlier at position 4, instead of at position 3. Then another clone is blocked again at position 4 in frame 39, and still another clone at position 4 again in frame 42.

So, what you have observed in frame 61 seems to have happened earlier in a similar fashion as I just described above.

(3)
As I mentioned in my last comment:

I would suggest you to print all the variables which the if-condition contains, right before the if-block. This way you will see better why that condition passes or fails (and hence why the code within that block is executed or not).

This may be relevant if you cannot spot any bug with regards to point (1).

1 Like

I am triying to store elevator_floors and elevator_pos values in a dictionary or list with no success. list or dict is created but the values are not appended. Why this very normal logic doesn’t work. Is there bug or something in the game?

There is no such bug in the game. Please tell us what language you use and show us the relevant lines in your code (no full code).

I am using python 3 and here is the code block that i am trying to run:

elevators = {}
for i in range(nb_elevators):
    # elevator_floor: floor on which this elevator is found
    # elevator_pos: position of the elevator on its floor
    elevator_floor, elevator_pos = [int(j) for j in input().split()]
    elevators[elevator_floor] = elevator_pos```
when i try to print the elevators dict after the for loop, it prints an empty dict

It works for me for the first two cases:

Could you copy what you see in your console here?


trying to do the same but doesnt work

It gives a key error since the dict stays empty

Try adding this line before the while loop:
print(elevators, file=sys.stderr, flush=True)

Also, which test case is that? If it is the first case, there is no elevator.


clone_floor equals to 0. And it shows the empty dictionary. This is the result for the first test case.

It’s perfectly correct because there is no elevator in the first case. Hence the dictionary must be empty.

i see now what the problem is. thanks for the help

1 Like

import sys
import math
nb_floors, width, nb_rounds, exit_floor, exit_pos, nb_total_clones, nb_additional_elevators, nb_elevators = [int(i) for i in input().split()]
dict_of_elevators={}
for i in range(nb_elevators):
elevator_floor, elevator_pos = [int(j) for j in input().split()]
dict_of_elevators[elevator_floor] = elevator_pos

while True:
inputs = input().split()
clone_floor = int(inputs[0]) # floor of the leading clone
clone_pos = int(inputs[1]) # position of the leading clone on its floor
direction = inputs[2] # direction of the leading clone: LEFT or RIGHT
elevator_floor = 0
if clone_floor < exit_floor:
if clone_pos > dict_of_elevators[elevator_floor]:
if direction == “RIGHT”:
elevator_floor+=1
print(“BLOCK”)
else:
print(“WAIT”)
elevator_floor+=1
else:
if exit_pos < clone_pos:
if direction == “LEFT”:
print(“WAIT”)
else:
print(“BLOCK”)

#general can someone explain to me why this ain’t working??? I’m bit idealess about things

Please edit your message and format the code properly using the </> button in the formatting toolbar, as currently it is not shown with any indentation. After that we can take a better look.

Hello. I have passed all the tests and validators except the first validator that does not work for my code.

Below is my code:

import sys
import math

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

# nb_floors: number of floors
# width: width of the area
# nb_rounds: maximum number of rounds
# exit_floor: floor on which the exit is found
# exit_pos: position of the exit on its floor
# nb_total_clones: number of generated clones
# nb_additional_elevators: ignore (always zero)
# nb_elevators: number of elevators
nb_floors, width, nb_rounds, exit_floor, exit_pos, nb_total_clones, nb_additional_elevators, nb_elevators = [int(i) for i in input().split()]

elevators = []

for i in range(nb_elevators):
    # elevator_floor: floor on which this elevator is found
    # elevator_pos: position of the elevator on its floor
    elevator_floor, elevator_pos = [int(j) for j in input().split()]
    elevators.append((elevator_floor, elevator_pos))
    elevators.sort(key=lambda x:x[0])
# game loop
while True:
    inputs = input().split()
    clone_floor = int(inputs[0])  # floor of the leading clone
    clone_pos = int(inputs[1])  # position of the leading clone on its floor
    direction = inputs[2]  # direction of the leading clone: LEFT or RIGHT


    if clone_pos == 0 or clone_pos == width-1:
       print("BLOCK")
    elif clone_floor!=exit_floor and ((clone_pos-elevators[clone_floor][1] > 0 and direction == "RIGHT") or (clone_pos-elevators[clone_floor][1] < 0 and direction == "LEFT")):
        print("BLOCK")
    elif clone_floor == exit_floor and clone_floor!=0 and ((clone_pos-exit_pos > 0 and direction == "RIGHT") or (clone_pos-exit_pos < 0 and direction == "LEFT")):
        print("BLOCK")
    else:
        print("WAIT")

I’m looking for some help.

Edit:
I got a way to solve the problem:
In the first validator, when the first clone is blocked, the following turn has not generated a new clone yet. Therefore we should find sufficient conditions to print(“WAIT”) in this case.

I can’t pass test 4 for some reason… it always glitch out at the latest floors (using C#).
No matter how many checks I do or how many variables and arrays so to make sure I get the correct position of each floor’s elevator… it always behaves weirdly at the latest floors…

That means your code is still buggy somewhere. If you want, you may PM me your code and I’ll take a look.

I created an int array named “elevators” and I set the size of the array to 10
Then in the FOR I added the line:

elevators[elevatorFloor] = elevatorPos;

inside at the end, in the hopes that the positions of the elevator would be saved in each index.

Then in the While section, I inserted this code:
if (cloneFloor == 0){
_if (exitFloor == cloneFloor){
__lastFloor = true;
___if (exitPos > clonePos){
____if (direction == "LEFT"){
____Console.WriteLine("BLOCK");
____}
___}
___if (exitPos < clonePos){
____if (direction == "RIGHT"){
_____Console.WriteLine("BLOCK");
____}
___}
__}
__if (exitFloor > cloneFloor && lastFloor == false){
___if (elevators[0] > clonePos){
____if (direction == "LEFT"){
_____Console.WriteLine("BLOCK");
____}
___}
___if (elevators[0] < clonePos){
____if (direction == "RIGHT"){
_____Console.WriteLine("BLOCK");
____}
___}
__}
_}
I repeated that code for each floor (replacing the corresponding number for each floor.

EDIT: I’m aware that I am creating too many steps, but I was not looking for efficiency, just to find why its not working

As I said, it’s better to PM me your code (rather than post your code here). But anyway…

You may format your code properly by using the </> button in the formatting toolbar. It’s difficult to read your current code.

Also, I don’t know whether your code outputs “WAIT” properly as the relevant code is not found.

Please PM me your code to further discuss if necessary.