Exemplo n.º 1
0
        public int ProcessCaves(string[] input, bool processSmallCaveTwice = false)
        {
            Dictionary <string, Cave> caves = new Dictionary <string, Cave>();

            for (int i = 0; i < input.Length; i++)
            {
                string[] relation       = input[i].Split('-');
                string   firstCaveName  = relation[0];
                string   secondCaveName = relation[1];
                Cave     firstCaveInfo  = new Cave(firstCaveName);
                Cave     secondCaveInfo = new Cave(secondCaveName);
                if (caves.ContainsKey(firstCaveName))
                {
                    firstCaveInfo = caves[firstCaveName];
                }
                else
                {
                    caves.Add(firstCaveName, firstCaveInfo);
                }
                if (caves.ContainsKey(secondCaveName))
                {
                    secondCaveInfo = caves[secondCaveName];
                }
                else
                {
                    caves.Add(secondCaveName, secondCaveInfo);
                }

                secondCaveInfo.AddConnectedCave(firstCaveInfo);
                firstCaveInfo.AddConnectedCave(secondCaveInfo);
            }

            int  pathCount = 0;
            Cave startCave = caves["start"];

            foreach (KeyValuePair <string, Cave> cave in startCave.ConnectedCaves)
            {
                List <Cave> previousExploredCaves = new List <Cave>();
                previousExploredCaves.Add(cave.Value);
                pathCount += ProcessPath(cave.Value, previousExploredCaves, processSmallCaveTwice);
            }

            return(pathCount);
        }