using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { public class Day01Part1 : Answerable { public override int Year { get; set; } = 2023; public override int Day { get; set; } = 1; public override int Part { get; set; } = 1; public override string GetAnswer(byte[] data) { return GetAsStringArray(data) .Select(GetValueFromLine) .Sum() .ToString(); } private int GetValueFromLine(string line) { // get all the numers MatchCollection collection = Regex.Matches(line, @"\d"); // merge first and last index as one string values = collection[0].Value + collection[^1].Value; // make an int return int.Parse(values); } } }