AdventOfCode/AdventOfCode.Solutions/2023/Day 01/Day01Part1.cs
Rob 3846b42b7e Massive code base change
partial completion of day 3
2023-12-03 19:09:26 +01:00

32 lines
865 B
C#

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);
}
}
}