32 lines
851 B
C#
32 lines
851 B
C#
using _2024;
|
|
|
|
Console.Write("Enter a day: ");
|
|
var input = Console.ReadLine();
|
|
|
|
if (!int.TryParse(input, out var day)) {
|
|
Console.Error.WriteLine("Error: input is not a valid integer.");
|
|
Environment.Exit(1);
|
|
}
|
|
|
|
if (day is < 1 or > 25) {
|
|
Console.Error.WriteLine("Error: day must be between 1 and 25.");
|
|
Environment.Exit(1);
|
|
}
|
|
|
|
var dayStr = day.ToString();
|
|
if (day < 10) {
|
|
dayStr = "0" + dayStr;
|
|
}
|
|
|
|
// Instantiate an ISolution named 's' based on the day, e.g., Day02 for day == 2, then run it
|
|
var typeName = $"_2024.Day{dayStr}";
|
|
var type = typeof(ISolution).Assembly.GetType(typeName);
|
|
|
|
if (type is null || !typeof(ISolution).IsAssignableFrom(type)) {
|
|
Console.Error.WriteLine($"Error: could not find a solution class for day {dayStr}.");
|
|
Environment.Exit(1);
|
|
}
|
|
|
|
var s = (ISolution)Activator.CreateInstance(type)!;
|
|
s.Run();
|