Пример #1
0
        public void Start(string[] args)
        {
            isSolving = true;
            string puzzleInput;

            while (isSolving)
            {
                Console.WriteLine("Enter Puzzle day and part: day,part");
                puzzleInput = Console.ReadLine();

                if (puzzleInput.StartsWith('q'))
                {
                    isSolving = false;
                    continue;
                }

                if (!GetDayAndPart(puzzleInput, out day, out part))
                {
                    Console.WriteLine("Invalid input..");
                    continue;
                }

                puzzleToSolve = puzzleFactory.GetPuzzle(day, part);

                if (puzzleToSolve != null)
                {
                    Console.WriteLine("Solution: " + puzzleToSolve.GetSolution());
                }
                else
                {
                    Console.WriteLine("Puzzle not found..");
                }
            }
        }
Пример #2
0
        public PuzzleBase GetPuzzle(int day, int part)
        {
            Type puzzleType = GetPuzzleType(day, part);

            if (puzzleType == null || puzzleType.GetTypeInfo().IsAbstract)
            {
                return(null);
            }

            if (puzzlesCacheDictionary.ContainsKey(puzzleType))
            {
                return(puzzlesCacheDictionary[puzzleType]);
            }

            PuzzleBase puzzle = (PuzzleBase)Activator.CreateInstance(puzzleType);

            puzzlesCacheDictionary.Add(puzzleType, puzzle);

            puzzle.Initialize();

            return(puzzle);
        }