using System.Text.RegularExpressions; namespace Day7; public partial class Parser { [GeneratedRegex(@"(\S+)\s+(\d+)")] private partial Regex HandMatch(); public IEnumerable Parse(string inputFile) { using var reader = File.OpenText(inputFile); while (!reader.EndOfStream) { var line = reader.ReadLine()!; var match = HandMatch().Match(line); if (!match.Success) { throw new Exception($"Expected hand and bid, but got: {line}"); } yield return new Hand(match.Groups[1].Value, int.Parse(match.Groups[2].Value)); } } }