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; } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); puzzleToSolve = puzzleFactory.GetPuzzle(day, part); if (puzzleToSolve != null) { Console.WriteLine("Solution: " + puzzleToSolve.GetSolution()); } else { Console.WriteLine("Puzzle not found.."); } stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds + "ms " + stopwatch.ElapsedTicks + "ticks"); } }
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); }