Don't Panic - Episode 1 - Puzzle discussion

Maybe you should start with an easier language?

I wouldn’t give up, and then I need to learn bash for work.

For a complete beginner I’d advise to solve less dificult puzzles first, such as The Descent, Temperatures, Power of Thor ep.1, Mars Lander ep.1, Horse-racing Duals.

Has anyone else had the issue of running out of time on test case 6 and 7? I’m blocking my clone as soon as they get out of the elevator if the next one is in the opposite direction, but I run out of time at the very end and I don’t know how I could make the direction change any more efficient.
Game Replay - CodinGame

There are no elevators on the last floor. Check for exits first, then for elevators.

1 Like

Why would the frames available for the round vary based on the code I place in the game loop?

I can make it vary on the Uturn case anywhere between 1 frame to 30+ frames, but I would assume that would be constant

Salut ! ces variables ne sont disponibles qu’au sein de la boucle dans laquelle elles sont dĂ©clarĂ©es. Tu dois les stocker au fur et Ă  mesure des itĂ©rations pour les utiliser aprĂ©s.

Hello everyone, I am unable to detect the problem in my script in 5th test case why is the bot getting blocked can anyone explain

using System;

using System.Linq;

using System.IO;

using System.Text;

using System.Collections;

using System.Collections.Generic;

/**

  • Auto-generated code below aims at helping you parse

  • the standard input according to the problem statement.

**/

class Player

{

static void Main(string[] args)

{

   

    string[] inputs;

    inputs = Console.ReadLine().Split(' ');

    int nbFloors = int.Parse(inputs[0]); // number of floors

    int width = int.Parse(inputs[1]); // width of the area

    int nbRounds = int.Parse(inputs[2]); // maximum number of rounds

    int exitFloor = int.Parse(inputs[3]); // floor on which the exit is found

    int exitPos = int.Parse(inputs[4]); // position of the exit on its floor

    int nbTotalClones = int.Parse(inputs[5]); // number of generated clones

    int nbAdditionalElevators = int.Parse(inputs[6]); // ignore (always zero)

    int nbElevators = int.Parse(inputs[7]); // number of elevators

    int[]elev=new int[nbElevators];

    for (int i = 0; i < nbElevators; i++)

    {

        inputs = Console.ReadLine().Split(' ');

        int elevatorFloor = int.Parse(inputs[0]); // floor on which this elevator is found

        int elevatorPos = int.Parse(inputs[1]); // position of the elevator on its floor

        elev[i]=elevatorPos;

    }

    // game loop

    while (true)

    {

        inputs = Console.ReadLine().Split(' ');

        int cloneFloor = int.Parse(inputs[0]); // floor of the leading clone

        int clonePos = int.Parse(inputs[1]); // position of the leading clone on its floor

        string direction = inputs[2]; // direction of the leading clone: LEFT or RIGHT

        int destinationPos;

       

        try{

            destinationPos=elev[cloneFloor];

           

        }catch(IndexOutOfRangeException ex){

            destinationPos=exitPos;

        }

        bool onEdge(){

            return((clonePos==width-1)||(clonePos==0));

        };

        // Write an action using Console.WriteLine()

        // To debug: Console.Error.WriteLine("Debug messages...");

        if(onEdge() ){

            Console.WriteLine("BLOCK");

        }else if(!onEdge() && (destinationPos>=clonePos && direction=="RIGHT") || (destinationPos<=clonePos && direction=="LEFT")){

            Console.WriteLine("WAIT");

        }else if(!onEdge() && (destinationPos>clonePos && direction=="LEFT") || (destinationPos<clonePos && direction=="RIGHT")){

            Console.WriteLine("BLOCK"+"!!!");

           

        }else{

            Console.WriteLine("WAIT");

        }

       

        /*if( (destinationPos>clonePos && direction=="RIGHT") || (destinationPos<clonePos && direction=="LEFT") ){

            Console.WriteLine("WAIT");

        }else{

            Console.WriteLine("BLOCK");

        }*/

       

        //else if((exitPos>clonePos && direction=="LEFT") || (exitPos<clonePos && direction=="RIGHT")) {

        //    Console.WriteLine("BLOCK");

        //}

        /*if(clonePos==width-1 || clonePos==0 ){

            Console.WriteLine("BLOCK");

        }else{

            Console.WriteLine("WAIT");

        }*/

         // action: WAIT or BLOCK

    }

}

}

You can print the values of the variables to the error stream for debugging. For example, if you add this line to your code before it prints BLOCK, you will see that one of the conditions set by your code to print the word is fulfilled:
Console.Error.WriteLine(destinationPos + " " + clonePos + " " + direction);
By the way, you can format your code on this forum by using the </> button in the toolbar :wink:

A little spoiler (in python):
if clone_floor == exit_floor: 
    if clone_pos > exit_pos: dir = 'LEFT'
    else: dir = 'RIGHT'
else:
    if clone_pos > el[clone_floor]: dir = 'LEFT'
    elif clone_pos == el[clone_floor]: dir = 'UP'
    else: dir = 'RIGHT'
if (direction == dir) or (dir == 'UP'): print('WAIT')
else: print('BLOCK')

This is the code for checking direction, with el is a dict saving pos of elevator for each floor
This will pass nearly all test cases except for ones that need to be blocked immediately U turn (test 1,3,5)
If you want to pass all test cases, check for clone_floor == -1.

Full code in python (don't watch if you haven't solved the poblem yet unless you are really stuck):
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()]
el = {}
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()]
    el[elevator_floor] = elevator_pos

# 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

    # Write an action using print
    # To debug: print("Debug messages...", file=sys.stderr, flush=True)

    # action: WAIT or BLOCK
    if clone_floor == -1: print('WAIT')
    else:
        if clone_floor == exit_floor: 
            if clone_pos > exit_pos: dir = 'LEFT'
            else: dir = 'RIGHT'
        else:
            if clone_pos > el[clone_floor]: dir = 'LEFT'
            elif clone_pos == el[clone_floor]: dir = 'UP'
            else: dir = 'RIGHT'
        if (direction == dir) or (dir == 'UP'): print('WAIT')
        else: print('BLOCK')

You can use the spoiler tag to enclose the spoiler. It can be found on the last button on the formatting toolbar - look for “Hide Details”. :wink:

Thanks a lot.

Continuing the discussion from Don't Panic - Episode 1 - Puzzle discussion:

all test cases are passing since first “Submit” but score stays 85% and as “U Turn” test fails on submit!

hi. first, sorry for my english. i don t undestand , is it bugged ?
in the lvl05, i try if (a>b) console.writeline(a +" "+b) the ouput answer is 0 14
so, anyone can look my program and say me if it s ok? thank you


    static void Main(string[] args)

    {

        string[] inputs;

        inputs = Console.ReadLine().Split(' ');

        int nbFloors = int.Parse(inputs[0]); // number of floors

        int width = int.Parse(inputs[1]); // width of the area

        int nbRounds = int.Parse(inputs[2]); // maximum number of rounds

        int exitFloor = int.Parse(inputs[3]); // floor on which the exit is found

        int exitPos = int.Parse(inputs[4]); // position of the exit on its floor

        int nbTotalClones = int.Parse(inputs[5]); // number of generated clones

        int nbAdditionalElevators = int.Parse(inputs[6]); // ignore (always zero)

        int nbElevators = int.Parse(inputs[7]); // number of elevators

        List<int> lE = new List<int>();

        for (int i = 0; i < nbElevators; i++)

        {

            inputs = Console.ReadLine().Split(' ');

            int elevatorFloor = int.Parse(inputs[0]); // floor on which this elevator is found

            int elevatorPos = int.Parse(inputs[1]); // position of the elevator on its floor

            lE.Add(elevatorPos);

        }

        string message="WAIT";

        lE.Add(exitPos);

       

        while (true)

        {

            inputs = Console.ReadLine().Split(' ');

            int cloneFloor = int.Parse(inputs[0]); // floor of the leading clone

            int clonePos = int.Parse(inputs[1]); // position of the leading clone on its floor

            string direction = inputs[2]; // direction of the leading clone: LEFT or RIGHT

           

            // Write an action using Console.WriteLine()

            // To debug: Console.Error.WriteLine("Debug messages...");

            if ((cloneFloor==-1)||(clonePos==-1))

            {

                message="WAIT";

            }else

            if((clonePos==0)||(clonePos==width-1))

            {

                message="BLOCK";

            }else

            if (((direction=="RIGHT")&&(clonePos>lE[cloneFloor]))||

                ((direction=="LEFT")&&(clonePos<lE[cloneFloor])))

            {

                message="BLOCK";

            }else

            {

                message="WAIT";

            }

            //message=lE[nbElevators-1].ToString();

            Console.WriteLine(message); // action: WAIT or BLOCK

           

        }

    }

}

Please format your code properly by using the </> button on the formatting toolbar, thanks.

Back to your question: the issue lies with
lE.Add(elevatorPos);
If you do a Console.Error.WriteLine, you will find that the elevator positions are not given in the order from ground floor to upper floors.

:star_struck: thank you

hey i managed to make a algorithm that can change the direction of the robots depending on the elevator position and exit position but i have trouble getting elevator position to update when the clone enters a new floor, anyone have any ideas on how to help with this problem?

All the elevator positions are given in the first turn and you need to store them using some kind of variable / data structure for use in subsequent turns.

in that case how exactly do i save all the elevator positions? I’m still pretty new to coding but i know some of the basics I’m currently trying out java

There are a few possibilities, e.g. hashmaps, integer arrays.