1
- using System . Diagnostics ;
2
-
3
- namespace Util . Aoc ;
4
-
5
- public class Solver
6
- {
7
- public delegate TInput Reader < TInput > ( string file ) ;
8
-
9
- public delegate TResult Part1 < TInput , TResult > ( TInput data ) ;
10
-
11
- public delegate TResult Part2 < TInput , TResult > ( TInput data ) ;
12
-
13
- public static void RunExamples < TInput , TPart1Result , TPart2Result > (
14
- int year ,
15
- string day ,
16
- Reader < TInput > reader ,
17
- Part1 < TInput , TPart1Result > part1 ,
18
- Part2 < TInput , TPart2Result > part2
19
- ) {
20
- string dirPath = Path . Combine ( Aoc . RootDirectory , $ "{ year } /d{ day } /test-runs") ;
21
-
22
- if ( Directory . Exists ( dirPath ) )
23
- {
24
- var testFiles = Directory . GetFiles ( dirPath ) ;
25
-
26
- foreach ( var file in testFiles )
27
- {
28
- TInput testData = reader ( file ) ;
29
-
30
- var stopwatch = Stopwatch . StartNew ( ) ;
31
- TPart1Result valuePart1 = part1 ( testData ) ;
32
- stopwatch . Stop ( ) ;
33
- Printer . ExamplePart1 ( valuePart1 , Path . GetFileName ( file ) , stopwatch . Elapsed . TotalMilliseconds ) ;
34
-
35
- stopwatch . Restart ( ) ;
36
- TPart2Result valuePart2 = part2 ( testData ) ;
37
- stopwatch . Stop ( ) ;
38
- Printer . ExamplePart2 ( valuePart2 , Path . GetFileName ( file ) , stopwatch . Elapsed . TotalMilliseconds ) ;
39
- }
40
- }
41
- }
42
-
43
- public static void RunSolution < TInput , TPart1Result , TPart2Result > (
44
- int year , string day , Reader < TInput > reader , Part1 < TInput , TPart1Result > part1 , Part2 < TInput , TPart2Result > part2
45
- )
46
- {
47
- string filePath = Path . Combine ( Aoc . RootDirectory , $ "{ year } /d{ day } /input.txt") ;
48
- TInput data = reader ( filePath ) ;
49
-
50
- var stopwatch = Stopwatch . StartNew ( ) ;
51
- TPart1Result valuePart1 = part1 ( data ) ;
52
- stopwatch . Stop ( ) ;
53
- Printer . SolutionPart1 ( valuePart1 , stopwatch . Elapsed . TotalMilliseconds ) ;
54
-
55
- stopwatch . Restart ( ) ;
56
- TPart2Result valuePart2 = part2 ( data ) ;
57
- stopwatch . Stop ( ) ;
58
- Printer . SolutionPart2 ( valuePart2 , stopwatch . Elapsed . TotalMilliseconds ) ;
59
- }
60
- }
1
+ using System . Diagnostics ;
2
+
3
+ namespace Util . Aoc ;
4
+
5
+ public class Solver
6
+ {
7
+ public delegate TInput Reader < TInput > ( string file ) ;
8
+
9
+ public delegate TResult Part1 < TInput , TResult > ( TInput data ) ;
10
+
11
+ public delegate TResult Part2 < TInput , TResult > ( TInput data ) ;
12
+
13
+ public static void RunExamples < TInput , TPart1Result , TPart2Result > (
14
+ int year ,
15
+ string day ,
16
+ Reader < TInput > reader ,
17
+ Part1 < TInput , TPart1Result > part1 ,
18
+ Part2 < TInput , TPart2Result > part2
19
+ )
20
+ {
21
+ string dirPath = Path . Combine ( Aoc . RootDirectory , $ "{ year } /d{ day } /test-runs") ;
22
+
23
+ if ( Directory . Exists ( dirPath ) )
24
+ {
25
+ var testFiles = Directory . GetFiles ( dirPath ) ;
26
+
27
+ foreach ( var file in testFiles )
28
+ {
29
+ TInput testData = reader ( file ) ;
30
+
31
+ var stopwatch = Stopwatch . StartNew ( ) ;
32
+ TPart1Result valuePart1 = part1 ( testData ) ;
33
+ stopwatch . Stop ( ) ;
34
+ Printer . ExamplePart1 ( valuePart1 , Path . GetFileName ( file ) , stopwatch . Elapsed . TotalMilliseconds ) ;
35
+
36
+ stopwatch . Restart ( ) ;
37
+ TPart2Result valuePart2 = part2 ( testData ) ;
38
+ stopwatch . Stop ( ) ;
39
+ Printer . ExamplePart2 ( valuePart2 , Path . GetFileName ( file ) , stopwatch . Elapsed . TotalMilliseconds ) ;
40
+ }
41
+ }
42
+ }
43
+
44
+ public static void RunSolution < TInput , TPart1Result , TPart2Result > (
45
+ int year , string day , Reader < TInput > reader , Part1 < TInput , TPart1Result > part1 , Part2 < TInput , TPart2Result > part2
46
+ )
47
+ {
48
+ string filePath = Path . Combine ( Aoc . RootDirectory , $ "{ year } /d{ day } /input.txt") ;
49
+ TInput data = reader ( filePath ) ;
50
+
51
+ var stopwatch = Stopwatch . StartNew ( ) ;
52
+ TPart1Result valuePart1 = part1 ( data ) ;
53
+ stopwatch . Stop ( ) ;
54
+ Printer . SolutionPart1 ( valuePart1 , stopwatch . Elapsed . TotalMilliseconds ) ;
55
+
56
+ stopwatch . Restart ( ) ;
57
+ TPart2Result valuePart2 = part2 ( data ) ;
58
+ stopwatch . Stop ( ) ;
59
+ Printer . SolutionPart2 ( valuePart2 , stopwatch . Elapsed . TotalMilliseconds ) ;
60
+ }
61
+ }
0 commit comments