gonna break the unit tests...
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
2015 day 12 p1 works but part 2 is over counting
This commit is contained in:
parent
a5beb2c1f0
commit
0caf534d83
|
@ -17,6 +17,7 @@ public class Test2015
|
||||||
[DataRow(typeof(Day09), "117", "909")]
|
[DataRow(typeof(Day09), "117", "909")]
|
||||||
[DataRow(typeof(Day10), "492982", "6989950")]
|
[DataRow(typeof(Day10), "492982", "6989950")]
|
||||||
[DataRow(typeof(Day11), "hepxxyzz", "heqaabcc")]
|
[DataRow(typeof(Day11), "hepxxyzz", "heqaabcc")]
|
||||||
|
[DataRow(typeof(Day12), "111754", "")]
|
||||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
Common.CheckDay(dayType, part1, part2);
|
Common.CheckDay(dayType, part1, part2);
|
||||||
|
|
|
@ -1,15 +1,49 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace AOC2015;
|
namespace AOC2015;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Day 12: <a href="https://adventofcode.com/2015/day/12"/>
|
/// Day 12: <a href="https://adventofcode.com/2015/day/12"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Day12 : Day
|
public sealed partial class Day12 : Day
|
||||||
{
|
{
|
||||||
public Day12() : base(2015, 12, "JSAbacusFramework.io")
|
public Day12() : base(2015, 12, "JSAbacusFramework.io")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"-?\d+")]
|
||||||
|
private static partial Regex Digits();
|
||||||
|
|
||||||
public override object Part1() => "";
|
public override object Part1() =>
|
||||||
|
Digits().Matches(Input.First()).Sum(n => int.Parse(n.Value));
|
||||||
|
|
||||||
public override object Part2() => "";
|
public override object Part2()
|
||||||
|
{
|
||||||
|
var reader = new Utf8JsonReader(File.ReadAllBytes(FileName));
|
||||||
|
var sum = 0;
|
||||||
|
bool redObject = false, insideObject = false;
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonTokenType.StartObject:
|
||||||
|
insideObject = true;
|
||||||
|
break;
|
||||||
|
case JsonTokenType.EndObject:
|
||||||
|
insideObject = false;
|
||||||
|
redObject = false;
|
||||||
|
break;
|
||||||
|
case JsonTokenType.String:
|
||||||
|
if (insideObject && reader.GetString()! == "red")
|
||||||
|
redObject = true;
|
||||||
|
break;
|
||||||
|
case JsonTokenType.Number:
|
||||||
|
if (!redObject) sum += reader.GetInt32();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue