Ejemplo n.º 1
0
        public static BigInteger GetDay24Part2Answer()
        {
            // Starting with your scan, how many bugs are present after 200
            // minutes?
            // Answer: 2065
            var mapDefinition = GetDay24Input();
            var currentState  = ErisMapState.CreateMap(mapDefinition, true);

            currentState.DrawMapState();
            var statesVisited = new HashSet <ErisMapState>()
            {
                currentState
            };

            Console.WriteLine("Start");
            for (int loopCount = 0; loopCount < 200; loopCount++)
            {
                currentState = currentState.Evolve();
                if (statesVisited.Contains(currentState))
                {
                    break;
                }
                statesVisited.Add(currentState);
                Console.Write($" ---> [Minutes: {loopCount + 1}, MinZ: {currentState.MinZ}, MaxZ: {currentState.MaxZ}]");
            }
            Console.WriteLine($"...after 200 minute(s):");
            //currentState.DrawMapState();
            var result = currentState.BugCells.Count;

            return(result);
        }
Ejemplo n.º 2
0
        public static BigInteger GetDay24Part1Answer()
        {
            // What is the biodiversity rating for the first layout that
            // appears twice?
            // Answer: 10282017
            var mapDefinition = GetDay24Input();
            var currentState  = ErisMapState.CreateMap(mapDefinition, false);

            currentState.DrawMapState();
            var statesVisited = new HashSet <ErisMapState>()
            {
                currentState
            };
            int loopCount = 0;

            while (true)
            {
                loopCount++;
                currentState = currentState.Evolve();
                if (statesVisited.Contains(currentState))
                {
                    break;
                }
                statesVisited.Add(currentState);
            }
            Console.WriteLine($"...after {loopCount} minute(s):");
            currentState.DrawMapState();
            var result = currentState.GetBiodiversityRating(0);

            return(result);
        }
Ejemplo n.º 3
0
        public static BigInteger GetDay24Part2AnswerTest()
        {
            var mapDefinition = new string[]
            { "....#",
              "#..#.",
              "#.?##",
              "..#..",
              "#....", };
            var map = ErisMapState.CreateMap(mapDefinition, true);

            map.DrawMapState();
            Console.WriteLine("Start");
            for (int i = 0; i < 10; i++)
            {
                map = map.Evolve();
                Console.Write($" ---> [Minutes: {i + 1}, MinZ: {map.MinZ}, MaxZ: {map.MaxZ}]");
            }
            Console.WriteLine($"...after 10 minute(s):");
            map.DrawMapState();
            var result = map.BugCells.Count;

            return(result);
        }
Ejemplo n.º 4
0
        public static ErisMapState CreateMap(
            IList <string> mapDefinition,
            bool isRecursive)
        {
            int height   = mapDefinition.Count;
            int width    = mapDefinition.Max(row => row.Length);
            var bugCells = new HashSet <GridPoint3D>();

            for (int y = 0; y < mapDefinition.Count; y++)
            {
                var rowDefinition = mapDefinition[y];
                for (int x = 0; x < rowDefinition.Length; x++)
                {
                    var      cellDefinition = rowDefinition[x];
                    var      point          = new GridPoint3D(x, y, 0);
                    CellType cellType       = cellDefinition switch
                    {
                        '.' => CellType.Empty,
                        '#' => CellType.Bug,
                        _ => CellType.Empty,
                    };
                    if (CellType.Bug.Equals(cellType))
                    {
                        bugCells.Add(point);
                    }
                }
            }
            var result = new ErisMapState(
                bugCells: bugCells,
                width: width,
                height: height,
                minZ: 0,
                maxZ: 0,
                isRecursive: isRecursive);

            return(result);
        }