Exemplo n.º 1
0
        public void PartTwo()
        {
            //< Looking for IDs that are missing.. but also have existing +1/-1 seats


            var inputLines = Helpers.FileHelper.ParseFile(InputFile);
            //< Parse each input line into a final 'SeatID'
            var seatIDs = inputLines.Select(x => BoardingPass.GetSeatID(x));
            //< Get a map of all existing ID -> SeatID pairs
            var seatMap = seatIDs.ToDictionary(x => x.ID, x => x);

            var possible = new List <SeatID>();

            for (int x = 0; x < BoardingPass.Rows.Count(); x++)
            {
                for (int y = 0; y < BoardingPass.Columns.Count(); y++)
                {
                    var seatID = new SeatID(x, y);

                    if (!seatMap.ContainsKey(seatID.ID))
                    {
                        int prevID = seatID.ID - 1;
                        int nextID = seatID.ID + 1;

                        if (seatMap.ContainsKey(prevID) && seatMap.ContainsKey(nextID))
                        {
                            possible.Add(seatID);
                        }
                    }
                }
            }

            Assert.IsTrue(possible.Single().ID == 504);
        }
Exemplo n.º 2
0
        public void Test_KnownIDs()
        {
            foreach (var tup in KnownIDs)
            {
                var id = BoardingPass.GetSeatID(tup.Item1);

                Assert.IsTrue(id.ID == tup.Item2);
            }
        }
Exemplo n.º 3
0
        public void PartOne()
        {
            var inputLines = Helpers.FileHelper.ParseFile(InputFile);
            //< Parse each input line into a final 'SeatID'
            var seatIDs = inputLines.Select(x => BoardingPass.GetSeatID(x));
            //< Grab the largest 'SeatID.ID' encountered
            var maxID = seatIDs.Max(x => x.ID);

            //< Ensure we match that known result
            Assert.IsTrue(maxID == 878);
        }