-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
23 lines (21 loc) · 1.05 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Text.RegularExpressions;
namespace AdventOfCode
{
public static class Program
{
public static string YearToExecute = "2024";
public static void Main(string[] args)
{
foreach (string filename in Directory.GetFiles(Path.Join($"Yr{YearToExecute}"), "*??.txt"))
{
int day = int.Parse(Regex.Match(filename, "input([0-9]{2}).txt").Groups[1].Value);
// Reflection is used to dynamically access each day's class, instead of specifying each one individually
Console.WriteLine($"==== Day {day:00} ====");
string[] input = File.ReadAllText(filename).TrimEnd().Split('\n');
Console.WriteLine(Type.GetType($"AdventOfCode.Yr{YearToExecute}.D{day:00}")!.GetMethod("PartOne")!.Invoke(null, new object[] { input }));
Console.WriteLine(Type.GetType($"AdventOfCode.Yr{YearToExecute}.D{day:00}")!.GetMethod("PartTwo")!.Invoke(null, new object[] { input }));
Console.WriteLine();
}
}
}
}