85 lines
1.7 KiB
C#
85 lines
1.7 KiB
C#
using AOC2022.Puzzles;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
namespace AOC2022;
|
|
|
|
internal static class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
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);
|
|
if (!int.TryParse(fileName, out int 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 int 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<int> dayNumbers)
|
|
{
|
|
try
|
|
{
|
|
dayNumbers.ForEach(day =>
|
|
{
|
|
string instanceToCreate = "AOC2022.Puzzles.Day" + day;
|
|
Type? typeName = Type.GetType(typeName: instanceToCreate);
|
|
|
|
if (typeName != null)
|
|
{
|
|
if (Activator.CreateInstance(typeName) is IPuzzle puzzle)
|
|
{
|
|
puzzle.FirstPuzzle();
|
|
puzzle.SecondPuzzle();
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Something Broke");
|
|
}
|
|
}
|
|
});
|
|
}
|
|
catch (NotImplementedException nex)
|
|
{
|
|
Console.WriteLine(nex.Message);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
}
|
|
}
|