27 lines
750 B
C#
27 lines
750 B
C#
using AdventOfCode2024.Input.Parsers;
|
|
|
|
namespace Day1;
|
|
|
|
/// <summary>
|
|
/// Parses a Stream line by line for pairs of integers
|
|
/// </summary>
|
|
public class PairParser : TextLineParser<(int, int)>
|
|
{
|
|
protected override (int, int) ParseLine(string line)
|
|
{
|
|
var pair = line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
|
|
if (pair.Length < 2)
|
|
{
|
|
throw new ArgumentException("Invalid line");
|
|
}
|
|
|
|
var entryOneParsed = int.TryParse(pair[0], out var entryOne);
|
|
var entryTwoParsed = int.TryParse(pair[1], out var entryTwo);
|
|
if (!entryOneParsed || !entryTwoParsed)
|
|
{
|
|
throw new ArgumentException("Invalid line");
|
|
}
|
|
|
|
return (entryOne, entryTwo);
|
|
}
|
|
} |