2022-12-03 10:51:57 +00:00
|
|
|
using AOC2022.Puzzles;
|
|
|
|
|
|
|
|
namespace AOC2022;
|
|
|
|
|
|
|
|
internal static class Program
|
|
|
|
{
|
2022-12-03 15:15:28 +00:00
|
|
|
private static void Main(string[] args)
|
2022-12-03 10:51:57 +00:00
|
|
|
{
|
|
|
|
Console.WriteLine("Enter Days separated by space, like '1 2 3 4 5'");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var daysToProcess = new List<int>();
|
|
|
|
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);
|
2022-12-03 15:15:28 +00:00
|
|
|
if (!int.TryParse(fileName, out var dayNumber))
|
2022-12-03 10:51:57 +00:00
|
|
|
{
|
|
|
|
Console.WriteLine("Just name the files 1.txt or something ffs");
|
|
|
|
return;
|
|
|
|
}
|
2022-12-03 15:15:28 +00:00
|
|
|
|
2022-12-03 10:51:57 +00:00
|
|
|
daysToProcess.Add(dayNumber);
|
|
|
|
}
|
2022-12-03 15:15:28 +00:00
|
|
|
|
2022-12-03 10:51:57 +00:00
|
|
|
ProcessDays(daysToProcess);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach (var arg in args)
|
|
|
|
{
|
2022-12-03 15:15:28 +00:00
|
|
|
if (!int.TryParse(arg, out var dayNumber))
|
2022-12-03 10:51:57 +00:00
|
|
|
{
|
|
|
|
Console.WriteLine("Just enter the numbers dude");
|
|
|
|
return;
|
|
|
|
}
|
2022-12-03 15:15:28 +00:00
|
|
|
|
2022-12-03 10:51:57 +00:00
|
|
|
daysToProcess.Add(dayNumber);
|
|
|
|
}
|
2022-12-03 15:15:28 +00:00
|
|
|
|
2022-12-03 10:51:57 +00:00
|
|
|
ProcessDays(daysToProcess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Just enter the numbers dude");
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
|
}
|
|
|
|
}
|
2022-12-03 15:15:28 +00:00
|
|
|
|
2022-12-03 10:51:57 +00:00
|
|
|
private static void ProcessDays(List<int> dayNumbers)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
dayNumbers.ForEach(day =>
|
|
|
|
{
|
2022-12-03 15:15:28 +00:00
|
|
|
var instanceToCreate = "AOC2022.Puzzles.Day" + day;
|
|
|
|
var typeName = Type.GetType(typeName: instanceToCreate);
|
2022-12-03 10:51:57 +00:00
|
|
|
|
2022-12-03 11:36:05 +00:00
|
|
|
var linesInFile = File.ReadAllLines($"Inputs/{day}.txt");
|
2022-12-03 15:15:28 +00:00
|
|
|
if (typeName == null) return;
|
|
|
|
|
|
|
|
if (Activator.CreateInstance(typeName, new object[] {linesInFile}) is IPuzzle puzzle)
|
2022-12-03 10:51:57 +00:00
|
|
|
{
|
2022-12-03 15:15:28 +00:00
|
|
|
Console.WriteLine($"Day {day} answers");
|
|
|
|
puzzle.SolveFirstPuzzle();
|
|
|
|
puzzle.SolveSecondPuzzle();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine("Something Broke");
|
2022-12-03 10:51:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2022-12-03 15:15:28 +00:00
|
|
|
Console.WriteLine($"You broke it {e.Message}");
|
2022-12-03 10:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-03 15:15:28 +00:00
|
|
|
}
|