コード例 #1
0
        public static void Part_1(string input, bool pretty)
        {
            c_input_reader input_reader = new c_input_reader(input);

            int[] moves = input_reader.read_line()
                          .Split(',')
                          .Select(move => int.Parse(move))
                          .ToArray();

            List <c_bingo_board> boards = new List <c_bingo_board>();

            while (input_reader.has_more_lines())
            {
                c_bingo_board board = new c_bingo_board();
                board.read_from_lines(input_reader);
                boards.Add(board);
            }

            int winning_score = 0;

            foreach (int move in moves)
            {
                foreach (c_bingo_board board in boards)
                {
                    int score = board.check_move(move);

                    if (score != 0)
                    {
                        Console.WriteLine("We have a winner!");
                        Console.WriteLine();
                        board.print();
                        Console.WriteLine();
                        Console.WriteLine("Winning Move = " + move);

                        winning_score = score;
                        break;
                    }
                }

                if (winning_score != 0)
                {
                    break;
                }
            }

            Console.WriteLine("Winning Score = " + winning_score);
        }
コード例 #2
0
        public static void Part_2(string input, bool pretty)
        {
            c_input_reader input_reader = new c_input_reader(input);

            int[] moves = input_reader.read_line()
                          .Split(',')
                          .Select(move => int.Parse(move))
                          .ToArray();

            List <c_bingo_board> boards = new List <c_bingo_board>();

            while (input_reader.has_more_lines())
            {
                c_bingo_board board = new c_bingo_board();
                board.read_from_lines(input_reader);
                boards.Add(board);
            }

            c_bingo_board first_winning_board = null;
            c_bingo_board last_winning_board  = null;

            int           highest_score         = int.MinValue;
            c_bingo_board highest_scoring_board = null;

            int           lowest_score         = int.MaxValue;
            c_bingo_board lowest_scoring_board = null;

            foreach (int move in moves)
            {
                Console.WriteLine(move);

                foreach (c_bingo_board board in boards)
                {
                    board.check_move(move);

                    if (board.Winner)
                    {
                        board.print();
                        Console.WriteLine();

                        if (first_winning_board == null)
                        {
                            first_winning_board = board;
                        }

                        if (board.Score > highest_score)
                        {
                            highest_score         = board.Score;
                            highest_scoring_board = board;
                        }

                        if (board.Score < lowest_score)
                        {
                            lowest_score         = board.Score;
                            lowest_scoring_board = board;
                        }

                        last_winning_board = board;
                    }
                }

                boards = boards.Where(x => !x.Winner).ToList();
            }

            Console.WriteLine();

            Console.WriteLine("First Winning Board:");
            Console.WriteLine();
            first_winning_board.print();
            Console.WriteLine();
            Console.WriteLine("Winning Move = " + first_winning_board.Winning_Move);
            Console.WriteLine("Winning Score = " + first_winning_board.Score);

            Console.WriteLine();

            Console.WriteLine("Last Winning Board:");
            Console.WriteLine();
            last_winning_board.print();
            Console.WriteLine();
            Console.WriteLine("Winning Move = " + last_winning_board.Winning_Move);
            Console.WriteLine("Winning Score = " + last_winning_board.Score);

            Console.WriteLine();

            Console.WriteLine("Highest Scoring Board:");
            Console.WriteLine();
            highest_scoring_board.print();
            Console.WriteLine();
            Console.WriteLine("Winning Move = " + highest_scoring_board.Winning_Move);
            Console.WriteLine("Winning Score = " + highest_scoring_board.Score);

            Console.WriteLine();

            Console.WriteLine("Lowest Scoring Board:");
            Console.WriteLine();
            lowest_scoring_board.print();
            Console.WriteLine();
            Console.WriteLine("Winning Move = " + lowest_scoring_board.Winning_Move);
            Console.WriteLine("Winning Score = " + lowest_scoring_board.Score);

            Console.WriteLine();
        }