diff --git a/AOC.Test/Test2015.cs b/AOC.Test/Test2015.cs index e6f6fab..e779c95 100644 --- a/AOC.Test/Test2015.cs +++ b/AOC.Test/Test2015.cs @@ -13,6 +13,7 @@ public class Test2015 [DataRow(typeof(Day05), "258", "53")] // [DataRow(typeof(Day06), "543903", "14687245")] [DataRow(typeof(Day07), "3176", "14710")] + [DataRow(typeof(Day08), "1342", "2074")] public void TestAllDays(Type dayType, string part1, string part2) { Common.CheckDay(dayType, part1, part2); @@ -25,7 +26,8 @@ public class Test2015 // [DataRow(typeof(Day04), "609043", "6742839")] [DataRow(typeof(Day05), "1", "1")] [DataRow(typeof(Day06), "1000000", "1000000")] - // [DataRow(typeof(Day07), "", "")] // test input doesn't have "a" key + // [DataRow(typeof(Day07), "", "")] // test input doesn't have "a" wire + [DataRow(typeof(Day08), "12", "19")] public void CheckTestInputs(Type dayType, string part1, string part2) { Day.UseTestInput = true; diff --git a/AOC2015/Day08.cs b/AOC2015/Day08.cs index d9b20ae..8c46bc1 100644 --- a/AOC2015/Day08.cs +++ b/AOC2015/Day08.cs @@ -3,13 +3,19 @@ /// /// Day 8: /// -public sealed class Day08 : Day +public sealed partial class Day08 : Day { - public Day08() : base(2015, 8, "Puzzle Name") + [GeneratedRegex(@"^""(\\x..|\\.|.)*""$")] + private static partial Regex CharSet(); + + public Day08() : base(2015, 8, "Matchsticks") { } - public override object Part1() => ""; + int CharCount(string arg) => CharSet().Match(arg).Groups[1].Captures.Count; + int EncodedCount(string arg) => 2 + arg.Sum(c => c is '\\' or '\"' ? 2 : 1); - public override object Part2() => ""; + public override object Part1() => Input.Sum(line => line.Length) - Input.Sum(CharCount); + + public override object Part2() => Input.Sum(EncodedCount) - Input.Sum(line => line.Length); } diff --git a/AOC2015/input2015/test08.in b/AOC2015/input2015/test08.in new file mode 100644 index 0000000..3d32fb3 --- /dev/null +++ b/AOC2015/input2015/test08.in @@ -0,0 +1,4 @@ +"" +"abc" +"aaa\"aaa" +"\x27"