ben
/
aoc
1
0
Fork 0

2023 day 1
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Ben Harris 2023-12-01 01:00:24 -05:00
parent e7d1481a89
commit ce3334832f
4 changed files with 1045 additions and 6 deletions

View File

@ -6,7 +6,12 @@ namespace AOC.Test;
public class Test2023
{
[DataTestMethod]
[DataRow(typeof(Day01), "", "")]
[DataRow(typeof(Day01), "54331", "54518")]
public void CheckAllDays(Type dayType, string part1, string part2) =>
Common.CheckDay(dayType, part1, part2);
[DataTestMethod]
[DataRow(typeof(Day01), "142", "142")] // unfortunately p2 example is different
public void CheckTestInputs(Type dayType, string part1, string part2) =>
Common.CheckDay(dayType, part1, part2, true);
}

View File

@ -2,11 +2,41 @@ namespace AOC2023;
public class Day01() : Day(2023, 1, "Puzzle Name")
{
public override void ProcessInput()
{
}
private static readonly List<string> _singleDigits =
["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
public override object Part1() => "";
public override void ProcessInput()
{
}
public override object Part2() => "";
public override object Part1() =>
Input.Sum(line => (line.First(char.IsDigit) - '0') * 10 + (line.Last(char.IsDigit) - '0'));
public override object Part2()
{
return Input.Sum(line =>
{
List<int> digits = new();
for (var i = 0; i < line.Length; i++)
{
if (char.IsDigit(line[i]))
{
digits.Add(item: line[i] - '0');
continue;
}
foreach (var (digit, spelled) in _singleDigits.Indexed())
{
if (i + spelled.Length - 1 >= line.Length || line[i..(i + spelled.Length)] != spelled)
continue;
digits.Add(digit);
break;
}
}
return digits.First() * 10 + digits.Last();
});
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet