-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day06Part1.cs
37 lines (29 loc) · 1.08 KB
/
Day06Part1.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
using AdventOfCode.Util;
using Microsoft.Extensions.Logging;
namespace AdventOfCode.Solutions.Day06;
[Solution("Day06", "Part1")]
public class Day06Part1 : Day06
{
private readonly ILogger _logger;
public Day06Part1(ILogger<Day06Part1> logger) => _logger = logger;
public override void Run(string inputFile)
{
var result = ParseRaces(inputFile)
.Select(r => r.CountWaysToWin())
.Product();
_logger.LogInformation("The product of the number of ways to win in all races is [{result}].", result);
}
private static List<BoatRace<int>> ParseRaces(string inputFile)
{
var lines = inputFile.SplitByEOL();
var times = Expressions.Numbers()
.Matches(lines[0])
.Select(m => int.Parse(m.Value));
var distances = Expressions.Numbers()
.Matches(lines[1])
.Select(m => int.Parse(m.Value));
return times.Zip(distances)
.Select(column => new BoatRace<int>(column.First, column.Second))
.ToList();
}
}