コード例 #1
0
        public static void Main(string[] args)
        {
            Dictionary <string, IPuzzle> availablePuzzles = GetAvailablePuzzles();

            Console.WriteLine("Welcome to the AdventOfCode puzzle solver!");
            Console.WriteLine("Enter puzzle day:");
            string dayString = Console.ReadLine();

            if (int.TryParse(dayString, out int day))
            {
                Console.WriteLine("Enter puzzle day part:");
                string partString = Console.ReadLine();

                if (int.TryParse(partString, out int part))
                {
                    string puzzleIdentifier = PuzzleHelper.GetPuzzleIdentifier(day, part);
                    if (!availablePuzzles.ContainsKey(puzzleIdentifier))
                    {
                        Console.WriteLine("The entered puzzle cannot be found.");
                    }
                    else
                    {
                        IPuzzle puzzle = availablePuzzles[puzzleIdentifier];

                        string solution = puzzle.GetSolution();
                        Console.WriteLine($"Solution: {solution}");
                    }
                }
                else
                {
                    Console.WriteLine("The entered part is invalid!");
                }
            }
            else
            {
                Console.WriteLine("The entered day is invalid!");
            }

            Console.WriteLine("See you soon?");
        }