2023 day 1
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
e7d1481a89
commit
ce3334832f
|
@ -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);
|
||||
}
|
|
@ -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
|
@ -0,0 +1,4 @@
|
|||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
Loading…
Reference in New Issue