Don't Panic - Episode 2 - Puzzle discussion

Oopsi. I saw your code with hardcoded values, the fact it works for only two cases, and your question about the update of the test variable, and I extrapolated a little. Sorry for that. ^^’

EDIT:
Since I haven’t done this puzzle, I’m not the more qualified to help you with the details…

N. B In the future avoid to share complete code publicly. This one is not a probleme since it’s not fully working and need somme work. But pay attention.

You don’t represent the map as a graph, but the map as a node in a graph.

Sorry for my late answer, I did not see you have answered.

Finally I succeeded this puzzle, and the hardcoded variables was only for testing, you know im not sure of what I do, i dont know very well how to debug so I have to check everything, and to make sure my variables are correct sometimes I hardcode them, even i know its not the best way to do.
I think you advised me to not share my code to avoid spoiling of the puzzle ? Please excuse me for that, I thought my code had not something really useful for other, but maybe im wrong. Ill be more careful next times.

Thank you for your help.

Hi, me and a friend are trying to code a solution for this problem, but we are having some troubles with it. Would be too much trouble if you could send me the solution by mail? :sweat_smile::pray:

I don’t think anyone should just send you the solution.

At the end, I managed to found a BFS to find a solution, but for the last 3 test cases it’s to slow. I think of change it into an A*, but I don’t know how to find the heuristic. Can some one give me a tip for it?

A BFS shouldn’t be too slow.

Maybe you’re not pruning nodes that are already visited.
Also, no need to consider every single location as a potential place to stop, only some locations are relevant for that.

Hello everyone,
I have a problem with values changing themselves. I made it so that my elev_tab was equal concrete value in this case it was width=13, but after running the code with this couple of cout’s i got “13 9983498” and i have no idea why this is happening.

    cout<<elev_tab[0]<<" ";
    int clone_floor;  // floor of the leading clone
    int clone_pos;    // position of the leading clone on its floor
    string direction; // direction of the leading clone: LEFT or RIGHT
    cin >> clone_floor >> clone_pos >> direction;
    cin.ignore();
    cout<<elev_tab[0]<<endl;

Thanks for all kinds of help

Not really sure what you did with elev_tab as there was no other code related to that variable except for “cout”, so couldn’t tell what happened.

Also, for proper debugging, use cerr instead of cout:

// To debug: cerr << "Debug messages..." << endl;

Thank you for answering. I dropped this puzzle, after reading some more about it, because it was to hard for me right now, but your tip about cerr is realy helpful.

1 Like

Some tips for those who seek to solve this problem with a score of 100%.

Here are some questions you should try to answer to yourself:

  • Why does the puzzle give you an exceptionnaly extra large time for the first round?
  • Could this extra time be used to your advantage for some preprocessing?
  • Is it more about comparing different possible map configurations or should you try different layouts during a single unique path search?

This puzzle allow for extremely clean solutions that are as pleasing to the eye as a recipe if you keep things rationals while attempting to answer the questions I posted above.

i try this for best way

listAfaire = [
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“BLOCK”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
“WAIT”,
];

i don’t understand why lose

Not sure which test case you are talking about. Also, please check the messages in the console - they should tell you why you lose.

Hello, i try to complete this puzzle, up to now i reach 50% with BFS. but for “Better Path” i take the left column for ascending but fail at 47/47 round when touch the elevator under asp.
does someone had encounter that and advice for pass.
thanks for your help

Do you mean “Best Path” test or “Best Path” validator? There is no test or validator named “Better Path”.

Yes sorry i wrote quickly and missed yes i mean “best Path”

I assume you are talking about the validator not the test. Here is a replay of that case for your reference. You can click the “…” button at the bottom right corner to see the actions taken. https://www.codingame.com/replay/371029235

I talk about test sorry. But that replay show me what i guess i have to do but my code start by reversing. Thanks that help me to thinks more. That maybe just a ponderarion to add in my bfs node dequeuing i will look.

1 Like

Bonjour,
j’aimerai calculer la distance entre chaque élévateur d’un étage et de l étage supérieur et mettre ca dans une liste ( length , (floorA,posA),(floorB,posB))
malheureusement, le resultat n’est pas tout a fait la.
Est-ce que quelqu’un pourrait me dire ou je me suis trompé ? merci
je vous ai juste mis la partie que je voudrais travailler


Hello,
I would like to calculate the distance between each elevator of a floor and the upper floor and put that in a list ( length , (floorA,posA),(floorB,posB))
Unfortunately, the result is not quite there.
Could someone tell me where I was wrong? thank you
I just put the part that I would like to work on

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)
    {
        // variables
        string message="WAIT";
        var lElevatorFloor= new List<int>();
        var lElevatorPos=new List<int>();
        var lElevatorFP=new List<(int,int)>();
        var bExitFloorRescue=false;
        var bElevatorDo=false;
        var betterPos=0;
        int iElevatorPos =0;
        int nbElevatorReserved=0;
        
        //////////////////////////////////////////////////////////////////
        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]); // number of additional elevators that you can build
        int nbElevators = int.Parse(inputs[7]); // number of elevators
        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
            
            lElevatorFloor.Add(elevatorFloor);
            lElevatorPos.Add(elevatorPos);
            lElevatorFP.Add((elevatorFloor,elevatorPos));
            
        }
        lElevatorFP.Add((exitFloor,exitPos));
        int distance=0;
        var Result = new List<(int,List<(int,int)>,List<(int,int)>)>(); // distance, point A, point B
        int a=0;
        int b=0;
        for (int i=0;i<nbFloors-1;i++)
        {
            
            var lA=new List<(int,int)>();
            foreach(var PointA in lElevatorFP)
            {
                lA.Clear();
                if (PointA.Item1.Equals(i))
                {
                    var lB=new List<(int,int)>();
                    foreach(var PointB in lElevatorFP)
                    {
                        lB.Clear();
                        if (PointB.Item1.Equals(i+1))
                        {
                            a=PointA.Item2;
                            Console.Error.WriteLine("PointA: "+ a);  
                            lA.Add((PointA.Item1,PointA.Item2));
                            b=PointB.Item2;
                            Console.Error.WriteLine(" PointB: "+b);  
                            lB.Add((PointB.Item1,PointB.Item2));
                            
                        }
                    distance = Math.Abs(a-b);
                    Console.Error.WriteLine("floor:"+i +" distance a:" +a + "b:"+b+" ="+distance);

                    Result.Add((distance,lA,lB));
                    }
                }
            }
        }    
       
        // game loop
        while (true)
        {
            Console.Error.WriteLine("reserved:"+nbElevatorReserved);
            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...");
            message="WAIT";
            
           
            /////////////////// OUTPUT ////////////////////////////
            Console.WriteLine(message); // action: WAIT or BLOCK//
            /////////////////////////////////////////////////////



        }
    }
}
///     (clonePos>lElevatorPos.IndexOf(lElevatorFloor.IndexOf(cloneFloor)))  ==> position clone > position elevator's floor (! 1st of the list)
///     (lElevatorFloor.Count(x=>x.Equals(cloneFloor))) ==> count nb of elevator / floor
///     Console.Error.WriteLine(lElevatorFloor.Count(x=>x.Equals(cloneFloor))); // nb elevator in clone floor
///     Console.Error.WriteLine(lElevatorFloor.Count(x=>x.Equals(exitFloor))); // nb elevator in exit floor (exit include)
             

Feedback:
The Episode 2 still has a wrong description of the nbAdditionalElevators. It states:

not used for this first question, value is always 0

It would be helpful to see the constraints of that value as well

1 Like