Exemplo n.º 1
0
        public BoardingPass ParseBoardingPassString(string input)
        {
            // Splits the Input string at the RowCount.

            char[] Chars;

            Chars = input.Substring(0, RowCount - 1).ToCharArray();
            UInt32 Row = this.BoardingPassValueToInt(Chars, 'B');

            Chars = input.Substring(RowCount - 1).ToCharArray();
            UInt32 Colum = this.BoardingPassValueToInt(Chars, 'R');

            BoardingPass retVal = new BoardingPass(Row, Colum);

            return(retVal);
        }
Exemplo n.º 2
0
        public static BoardingPass Parse(string input)
        {
            if (input.Length != 10)
            {
                throw new ArgumentException("10 Characters expected");
            }

            string rowInput  = input.Substring(0, 7);
            string seatInput = input.Substring(7, 3);

            BoardingPass pass = new BoardingPass();

            pass.Seat = CalculateSeat(seatInput);
            pass.Row  = CalculateRow(rowInput);
            return(pass);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Seat ID = RowNum * 8 + ColNum
        ///
        /// The seat ID will be sequential, meaning the next seatId is the previous seatId + 1. Just need
        /// to sort and find the empty seat! This would be easily solved without loops if seats weren't missing.
        /// </summary>
        static void Part2(IEnumerable <BoardingPass> boardingPasses)
        {
            var sortedBoardingPasses = boardingPasses.OrderBy(x => x.SeatId).ToArray();

            for (var i = 0; i < sortedBoardingPasses.Count() - 1; i++)
            {
                var currentBoardingPass = sortedBoardingPasses[i];
                var nextBoardingPass    = sortedBoardingPasses[i + 1];

                if (nextBoardingPass.SeatId - currentBoardingPass.SeatId != 1)
                {
                    var myBoardingPassColumn = currentBoardingPass.Column == 8 ? 0 : currentBoardingPass.Column + 1;
                    var myBoardingPassRow    = currentBoardingPass.Column == 8 ? nextBoardingPass.Row : currentBoardingPass.Row;
                    var myBoardingPass       = new BoardingPass(myBoardingPassRow, myBoardingPassColumn);
                    Console.WriteLine($"BoardingPassId: {myBoardingPass.SeatId}, Row: {myBoardingPass.Row}, Column: {myBoardingPass.Column}");
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var inputList      = (args.Count() > 0) ? InputLoader.GetInputAsList(args[0]) : InputLoader.GetInputAsList("input.txt");
            var boardingPasses = inputList.Select(anon => BoardingPass.ParseInput(anon)).ToList();
            var highestID      = boardingPasses.Max(anon => anon.SeatID);

            Console.WriteLine($"The highest seat ID (part 1): {highestID}");
            var emptySeats = new List <BoardingPass>();

            for (var i = 0; i < 128; i++)
            {
                for (var j = 0; j < 8; j++)
                {
                    var doesExistInPasses = boardingPasses
                                            .Where(anon => anon.SeatID.Equals(i * 8 + j))
                                            .Count();
                    if (doesExistInPasses == 0)
                    {
                        emptySeats.Add(new BoardingPass()
                        {
                            Row = i, Column = j
                        });
                    }
                }
            }
            foreach (var mySeat in emptySeats)
            {
                var leftSeatExists = boardingPasses
                                     .Where(anon => (mySeat.SeatID - 1).Equals(anon.SeatID))
                                     .Count() != 0;
                var rightSeatExists = boardingPasses
                                      .Where(anon => (mySeat.SeatID + 1).Equals(anon.SeatID))
                                      .Count() != 0;
                if (leftSeatExists && rightSeatExists)
                {
                    Console.WriteLine($"My seat is ID: {mySeat.SeatID}");
                }
            }
            Console.ReadLine();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string[] lines = System.IO.File.ReadAllLines(@"input.txt");

            List <BoardingPass> allCombinations = new List <BoardingPass>();

            for (int i = 0; i < 128; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    allCombinations.Add(new BoardingPass()
                    {
                        Row  = i,
                        Seat = j
                    });
                }
            }
            int highestSeatId          = 0;
            List <BoardingPass> passes = new List <BoardingPass>();

            foreach (string line in lines)
            {
                BoardingPass temp = BoardingPass.Parse(line);
                if (temp.SeatId > highestSeatId)
                {
                    highestSeatId = temp.SeatId;
                }

                passes.Add(temp);
                allCombinations.RemoveAll(x => x.Row == temp.Row && x.Seat == temp.Seat);
            }
            Console.WriteLine("Highest SeatId : " + highestSeatId);
            foreach (BoardingPass pass in allCombinations)
            {
                if (passes.Any(x => x.SeatId == pass.SeatId - 1) && passes.Any(x => x.SeatId == pass.SeatId + 1))
                {
                    Console.WriteLine($"Row {pass.Row}, Seat {pass.Seat}, SeatId {pass.SeatId}");
                }
            }
        }