/
BaseProblem.cs
55 lines (47 loc) · 2.04 KB
/
BaseProblem.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
namespace AoCHelper
{
public abstract class BaseProblem
{
protected virtual string ClassPrefix { get; } = "Problem";
/// <summary>
/// Expected input file dir path.
/// </summary>
protected virtual string InputFileDirPath { get; } = "Inputs";
/// <summary>
/// Expected input file extension.
/// </summary>
protected virtual string InputFileExtension { get; } = ".txt";
/// <summary>
/// Problem's index.
/// Two digit number, (expect a leading '0' when appropriated).
/// </summary>
/// <summary>
/// Extracts problem's index from the class name.
/// Supported formats: <see cref="ClassPrefix"/>{Index}, <see cref="ClassPrefix"/>_{Index}.
/// In case of unsupported class name format, <see cref="InputFilePath"/> needs to be overriden to point to the right input file.
/// </summary>
/// <returns>Problem's index or uint.MaxValue if unsupported class name.</returns>
public virtual uint CalculateIndex()
{
var typeName = GetType().Name;
return uint.TryParse(typeName.Substring(typeName.IndexOf(ClassPrefix) + ClassPrefix.Length).TrimStart('_'), out var index)
? index
: default;
}
/// <summary>
/// Expected input file path.
/// By default, <see cref="InputFileDirPath"/>/<see cref="CalculateIndex"/>.<see cref="InputFileExtension"/>.
/// Overriding it makes <see cref="ClassPrefix"/>, <see cref="InputFileDirPath"/>, <see cref="InputFileExtension"/> and <see cref="CalculateIndex"/> irrelevant
/// </summary>
public virtual string InputFilePath
{
get
{
var index = CalculateIndex().ToString("D2");
return Path.Combine(InputFileDirPath, $"{index}.{InputFileExtension.TrimStart('.')}");
}
}
public abstract ValueTask<string> Solve_1();
public abstract ValueTask<string> Solve_2();
}
}