-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
56 lines (46 loc) · 1.6 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using AdventOfCode.Solutions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode {
class Program {
public static async Task Main(string[] args) {
// What day
int day = 11; // DateTime.Now.Day;
if (args.Length > 0) {
day = Convert.ToInt32(args[0]);
}
// What input file
string file = $"Inputs/day-{day:00}.txt";
if (!File.Exists(file)) {
Console.WriteLine($"Input file not found => {file}");
return;
}
// Create solution instance
ISolution solution = CreateSolution(day);
if (solution == null) {
Console.WriteLine($"Solution not found => {solution}");
return;
}
// Read input
await solution.ReadInput(file);
// Execute part1
Console.WriteLine($"Part 1 ->");
solution.Part1();
Console.WriteLine(Environment.NewLine);
// Execute part2
Console.WriteLine($"Part 2 ->");
solution.Part2();
}
private static ISolution CreateSolution(int day) {
var className = $"Day{day:00}";
var assembly = Assembly.GetExecutingAssembly();
Type type = assembly.GetTypes().SingleOrDefault(x => x.Name == className);
return type != null ? Activator.CreateInstance(type) as ISolution : null;
}
}
}