-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAoCSolver.cs
78 lines (66 loc) · 2.13 KB
/
AoCSolver.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using AoC2016.Service;
using AoC2016.Solutions;
namespace AoC2016
{
public class AoCSolver
{
private readonly IChallengeDataService _dataService;
public AoCSolver(IChallengeDataService dataService)
{
_dataService = dataService;
}
public async Task Solve(int day)
{
ISolution solution;
try
{
solution = SolutionProvider.GetSolution(day);
}
catch (NotImplementedException)
{
Console.WriteLine($"Solution for day {day} not implemented");
return;
}
var content = await _dataService.GetAsync(day);
Task<string> example;
Task<string> silver;
Task<string> gold;
var exampleSw = new Stopwatch();
var silverSw = new Stopwatch();
var goldSw = new Stopwatch();
try
{
exampleSw.Start();
example = solution.SolveExampleAsync();
}
catch (NotImplementedException)
{
example = Task.FromResult("Not implemented");
}
try
{
silverSw.Start();
silver = solution.SolveSilverAsync(content);
}
catch (NotImplementedException)
{
silver = Task.FromResult("Not implemented");
}
try
{
goldSw.Start();
gold = solution.SolveGoldAsync(content);
}
catch (NotImplementedException)
{
gold = Task.FromResult("Not implemented");
}
Console.WriteLine($"Example solution for day {day}: {await example} ({exampleSw.ElapsedMilliseconds}ms)");
Console.WriteLine($"Silver solution for day {day}: {await silver} ({silverSw.ElapsedMilliseconds}ms)");
Console.WriteLine($"Gold solution for day {day}: {await gold} ({goldSw.ElapsedMilliseconds}ms)");
}
}
}