-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay04.cs
35 lines (31 loc) · 1.15 KB
/
Day04.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
using AdventOfCode.Inputs;
using AdventOfCode.Util;
namespace AdventOfCode.Solutions.Day04;
[InputFile(NamedInputs.Day04)]
[InputFile(NamedInputs.Day04Test1, InputFileType.Test)]
public abstract class Day04 : ISolution
{
public void Run(string inputFile)
{
var scratchCards = ParseScratchCards(inputFile);
RunPart(scratchCards);
}
protected abstract void RunPart(List<ScratchCard> card);
private static List<ScratchCard> ParseScratchCards(string inputFile)
=> Expressions.ScratchCardNumbers()
.Matches(inputFile)
.Select(m => new ScratchCard
{
CardNumber = int.Parse(m.Groups[1].ValueSpan),
WinningNumbers = Expressions.Numbers()
.Matches(m.Groups[2].Value)
.Select(wn => int.Parse(wn.ValueSpan))
.ToArray(),
YourNumbers = Expressions.Numbers()
.Matches(m.Groups[3].Value)
.Select(wn => int.Parse(wn.ValueSpan))
.ToArray()
}
)
.ToList();
}