Exemplo n.º 1
0
        private BoardsContainer GetBoards(string[] input)
        {
            BoardsContainer boardsContainer = new BoardsContainer();

            // Begin at second line
            for (int i = 1; i < input.Length; i += 6)
            {
                // First line is a jump
                Check[,] board = new Check[5, 5];

                // Check the next 5 lines
                for (int j = 1; j < 6; j++)
                {
                    MatchCollection values = Regex.Matches(input[i + j], @"(\d+)");
                    for (int k = 0; k < values.Count; k++)
                    {
                        board[j - 1, k] = new Check()
                        {
                            Value = int.Parse(values[k].Value)
                        };
                    }
                }

                boardsContainer.Boards.Add(board);
            }

            return(boardsContainer);
        }
Exemplo n.º 2
0
        protected override object ResolveFirstPart(string[] input)
        {
            BoardsContainer boardsContainer = GetBoards(input);
            MatchCollection draws           = Regex.Matches(input[0], @"(\d+)");

            for (int i = 0; i < draws.Count; i++)
            {
                int value = int.Parse(draws[i].Value);
                boardsContainer.MarkBoards(value);
                List <Check[, ]> winningBoards = boardsContainer.GetWinningBoards();

                if (winningBoards.Count != 0)
                {
                    return(boardsContainer.GetSumOfAllMarkedValues(winningBoards[0]) * value);
                }
            }

            return(-1);
        }
Exemplo n.º 3
0
        protected override object ResolveSecondPart(string[] input)
        {
            BoardsContainer boardsContainer       = GetBoards(input);
            MatchCollection draws                 = Regex.Matches(input[0], @"(\d+)");
            int             lastWinningBoardValue = 0;

            for (int i = 0; i < draws.Count; i++)
            {
                int value = int.Parse(draws[i].Value);
                boardsContainer.MarkBoards(value);
                List <Check[, ]> winningBoards = boardsContainer.GetWinningBoards();

                for (int j = 0; j < winningBoards.Count; j++)
                {
                    lastWinningBoardValue = boardsContainer.GetSumOfAllMarkedValues(winningBoards[j]) * value;
                    boardsContainer.Boards.Remove(winningBoards[j]);
                }
            }

            return(lastWinningBoardValue);
        }