using AOC2022.Puzzles; namespace AOC2022; internal static class Program { private static void Main(string[] args) { Console.WriteLine("Enter Days separated by space, like '1 2 3 4 5'"); try { var daysToProcess = new List(); if (args.Length == 0) { Console.WriteLine("No input processing all files in Input/ directory"); foreach (var file in Directory.GetFiles("Inputs/")) { var fileName = Path.GetFileNameWithoutExtension(file); if (!int.TryParse(fileName, out var dayNumber)) { Console.WriteLine("Just name the files 1.txt or something ffs"); return; } daysToProcess.Add(dayNumber); } ProcessDays(daysToProcess); } else { foreach (var arg in args) { if (!int.TryParse(arg, out var dayNumber)) { Console.WriteLine("Just enter the numbers dude"); return; } daysToProcess.Add(dayNumber); } ProcessDays(daysToProcess); } } catch (Exception e) { Console.WriteLine("Just enter the numbers dude"); Console.WriteLine(e.Message); } } private static void ProcessDays(List dayNumbers) { try { dayNumbers.ForEach(day => { var instanceToCreate = "AOC2022.Puzzles.Day" + day; var typeName = Type.GetType(typeName: instanceToCreate); var linesInFile = File.ReadAllLines($"Inputs/{day}.txt"); if (typeName == null) return; if (Activator.CreateInstance(typeName, new object[] {linesInFile}) is IPuzzle puzzle) { Console.WriteLine($"Day {day} answers"); puzzle.SolveFirstPuzzle(); puzzle.SolveSecondPuzzle(); } else { Console.WriteLine("Something Broke"); } }); } catch (Exception e) { Console.WriteLine($"You broke it {e.Message}"); } } }