1- namespace AdventOfCode . Commons ;
1+ using AdventOfCode . Commons . PuzzleInputReaderStrategy ;
2+
3+ namespace AdventOfCode . Commons ;
24
35/// <summary>
46/// Represent the solver used for a given day
1416public abstract class Solver < TInput , TResult >
1517{
1618 /// <summary>
17- /// The path to the input file (ex: <c>"day1/input.txt"</c>)
19+ /// The puzzle input
1820 /// </summary>
19- protected abstract string InputPath { get ; }
21+ public readonly Lazy < TInput > PuzzleInput ;
2022
21- public readonly TInput Input ;
23+ /// <summary>
24+ /// Create a new solver and initialize its puzzle input based on the provided <see cref="IPuzzleInputReaderStrategy"/>
25+ /// </summary>
26+ /// <param name="puzzleInputReader">The strategy to use to retriever the puzzle input</param>
27+ private Solver ( IPuzzleInputReaderStrategy puzzleInputReader )
28+ {
29+ PuzzleInput = new Lazy < TInput > ( ( ) =>
30+ {
31+ var content = puzzleInputReader . ReadInput ( ) ;
32+ return ParseInput ( content ) ;
33+ } ) ;
34+ }
2235
23- protected Solver ( )
24- => Input = ReadInput ( InputPath ) ;
36+ /// <summary>
37+ /// Create a new solver with a puzzle input located in a local file
38+ /// </summary>
39+ /// <param name="inputPath">The path to the file containing the input</param>
40+ protected Solver ( string inputPath )
41+ : this ( new LocalPuzzleInputReaderStrategy { InputPath = inputPath } ) { }
2542
2643 /// <summary>
27- /// Logic for the solution of the first part of the puzzle
44+ /// Create a new solver that will retrieve the puzzle input from the server
45+ /// </summary>
46+ /// <param name="year">The year of the current challenge</param>
47+ /// <param name="day">The day for which the puzzle input is needed</param>
48+ protected Solver ( int year , int day )
49+ : this ( new RemotePuzzleInputReaderStrategy { Year = year , Day = day } ) { }
50+
51+
52+ /// <summary>
53+ /// Parse the input file and convert it to <typeparamref name="TInput"/>
54+ /// for it to be used as the input of the <see cref="PartOne(TInput)"/>
55+ /// and <see cref="PartTwo(TInput)"/>
2856 /// </summary>
2957 ///
30- /// <param name="input ">
31- /// The digested puzzle input
58+ /// <param name="inputPath ">
59+ /// The path of your puzzle input
3260 /// </param>
3361 ///
3462 /// <returns>
35- /// The puzzle's solution
63+ /// The digested input
3664 /// </returns>
37- public abstract TResult PartOne ( TInput input ) ;
65+ public abstract TInput ParseInput ( IEnumerable < string > input ) ;
3866
3967 /// <summary>
40- /// Logic for the solution of the second part of the puzzle
68+ /// Logic for the solution of the first part of the puzzle
4169 /// </summary>
4270 ///
4371 /// <param name="input">
@@ -47,20 +75,18 @@ protected Solver()
4775 /// <returns>
4876 /// The puzzle's solution
4977 /// </returns>
50- public abstract TResult PartTwo ( TInput input ) ;
78+ public abstract TResult PartOne ( TInput input ) ;
5179
5280 /// <summary>
53- /// Parse the input file and convert it to <typeparamref name="TInput"/>
54- /// for it to be used as the input of the <see cref="PartOne(TInput)"/>
55- /// and <see cref="PartTwo(TInput)"/>
81+ /// Logic for the solution of the second part of the puzzle
5682 /// </summary>
5783 ///
58- /// <param name="inputPath ">
59- /// The path of your puzzle input
84+ /// <param name="input ">
85+ /// The digested puzzle input
6086 /// </param>
6187 ///
6288 /// <returns>
63- /// The digested input
89+ /// The puzzle's solution
6490 /// </returns>
65- public abstract TInput ReadInput ( string inputPath ) ;
91+ public abstract TResult PartTwo ( TInput input ) ;
6692}
0 commit comments