diff --git a/AOC.Test/Test2015.cs b/AOC.Test/Test2015.cs index 6434a05..d5ffd7b 100644 --- a/AOC.Test/Test2015.cs +++ b/AOC.Test/Test2015.cs @@ -15,6 +15,7 @@ public class Test2015 [DataRow(typeof(Day07), "3176", "14710")] [DataRow(typeof(Day08), "1342", "2074")] [DataRow(typeof(Day09), "117", "909")] + [DataRow(typeof(Day10), "492982", "6989950")] public void TestAllDays(Type dayType, string part1, string part2) { Common.CheckDay(dayType, part1, part2); @@ -30,6 +31,7 @@ public class Test2015 // [DataRow(typeof(Day07), "", "")] // test input doesn't have "a" wire [DataRow(typeof(Day08), "12", "19")] [DataRow(typeof(Day09), "605", "982")] + [DataRow(typeof(Day10), "237746", "3369156")] public void CheckTestInputs(Type dayType, string part1, string part2) { Day.UseTestInput = true; diff --git a/AOC2015/Day10.cs b/AOC2015/Day10.cs index 2b5dc9c..fef0f8b 100644 --- a/AOC2015/Day10.cs +++ b/AOC2015/Day10.cs @@ -5,11 +5,49 @@ /// public sealed class Day10 : Day { + private string _seed; + public Day10() : base(2015, 10, "Puzzle Name") { + _seed = Input.First(); } - public override object Part1() => ""; + public override object Part1() + { + for (var i = 0; i < 40; i++) + _seed = string.Concat(LookAndSay(_seed)); - public override object Part2() => ""; -} + return _seed.Length; + } + + public override object Part2() + { + for (var i = 0; i < 10; i++) + _seed = string.Concat(LookAndSay(_seed)); + + return _seed.Length; + } + + public static IEnumerable LookAndSay(string data) + { + var currentDigit = data[0]; + int count = 1, place = 1; + + while (place < data.Length) + { + if (data[place] == currentDigit) count++; + else + { + yield return count; + yield return currentDigit - '0'; + currentDigit = data[place]; + count = 1; + } + + place++; + } + + yield return count; + yield return currentDigit - '0'; + } +} \ No newline at end of file diff --git a/AOC2015/input2015/test10.in b/AOC2015/input2015/test10.in new file mode 100644 index 0000000..7270077 --- /dev/null +++ b/AOC2015/input2015/test10.in @@ -0,0 +1 @@ +111221