Esempio n. 1
0
        private static int SimulateFrom(SeatLayout startState)
        {
            Console.WriteLine($"start: \n\n{startState}\n\n");

            while (startState.GetNextState(out startState))
            {
                Console.WriteLine($"{startState}\n\n");
            }

            Console.WriteLine($"end: \n\n{startState}");
            return(startState.CountAllOccupied());
        }
Esempio n. 2
0
        /// <summary>
        /// Get next state of the seat layout based on the rules.
        /// </summary>
        /// <param name="nextLayout">out param for next state</param>
        /// <returns>if next state is different from this</returns>
        public bool GetNextState(out SeatLayout nextLayout)
        {
            bool isChanged = false;

            nextLayout = new SeatLayout(this);
            for (var i = 0; i < _grid.Count; i++)
            {
                var newRow = new List <char>();
                for (var j = 0; j < _grid[0].Count; j++)
                {
                    newRow.Add(NewSeat(i, j, ref isChanged));
                }
                nextLayout._grid.Add(newRow);
            }

            return(isChanged);
        }
Esempio n. 3
0
        public static int Part2(IEnumerable <string> lines)
        {
            var state = new SeatLayout(lines, 5, SeatLayout.NeighborMode.FirstToSee);

            return(SimulateFrom(state));
        }
Esempio n. 4
0
        public static int Part1(IEnumerable <string> lines)
        {
            var state = new SeatLayout(lines);

            return(SimulateFrom(state));
        }
Esempio n. 5
0
 private SeatLayout(SeatLayout otherLayout)
 {
     _grid = new List <List <char> >(); // !!! :/
     _occupiedToEmptyMin = otherLayout._occupiedToEmptyMin;
     _neighborMode       = otherLayout._neighborMode;
 }