using System.Text.RegularExpressions; namespace Day6; public partial class RaceTimeParser { [GeneratedRegex(@"\d+")] private partial Regex NumberList(); public IList Parse(string inputFile) { using var reader = File.OpenText(inputFile); var timesLine = reader.ReadLine()!; var times = NumberList().Matches(timesLine.Substring("Time:".Length)).Cast().Select(x => long.Parse(x.Value)).ToList(); var durationsLine = reader.ReadLine()!; var durations = NumberList().Matches(durationsLine.Substring("Distance:".Length)).Cast().Select(x => long.Parse(x.Value)).ToList(); if (times.Count != durations.Count) { throw new Exception("Expecting the same number of times and distances"); } return times.Zip(durations).Select(item => new RaceStats(item.First, item.Second)).ToList(); } }