diff --git a/aoc2021.test/DayTests.cs b/aoc2021.test/DayTests.cs index c8427a6..c57eead 100644 --- a/aoc2021.test/DayTests.cs +++ b/aoc2021.test/DayTests.cs @@ -44,6 +44,7 @@ public class DayTests [DataRow(typeof(Day03), "198", "230")] [DataRow(typeof(Day04), "4512", "1924")] [DataRow(typeof(Day05), "5", "12")] + [DataRow(typeof(Day06), "5934", "")] public void CheckTestInputs(Type dayType, string part1, string part2) { Day.UseTestInput = true; diff --git a/aoc2021/Day06.cs b/aoc2021/Day06.cs new file mode 100644 index 0000000..5783a44 --- /dev/null +++ b/aoc2021/Day06.cs @@ -0,0 +1,43 @@ +namespace aoc2021; + +/// +/// Day 6: +/// +public sealed class Day06 : Day +{ + private readonly List _fishes; + public Day06() : base(6, "Lanternfish") + { + //UseTestInput = true; + _fishes = Input.First().Split(',').Select(int.Parse).ToList(); + } + + private static List DayStep(List state) + { + List result = new(); + + foreach (var fish in state) + { + switch (fish) + { + case 0: + result.Add(6); + result.Add(8); + break; + default: + result.Add(fish - 1); + break; + } + } + + return result; + } + + public override string Part1() + { + var fishes = Enumerable.Range(0, 80).Aggregate(_fishes, (current, _) => DayStep(current)); + return $"{fishes.Count}"; + } + + public override string Part2() => ""; +} diff --git a/aoc2021/input/day06.in b/aoc2021/input/day06.in new file mode 100644 index 0000000..46b468a --- /dev/null +++ b/aoc2021/input/day06.in @@ -0,0 +1 @@ +3,3,5,1,1,3,4,2,3,4,3,1,1,3,3,1,5,4,4,1,4,1,1,1,3,3,2,3,3,4,2,5,1,4,1,2,2,4,2,5,1,2,2,1,1,1,1,4,5,4,3,1,4,4,4,5,1,1,4,3,4,2,1,1,1,1,5,2,1,4,2,4,2,5,5,5,3,3,5,4,5,1,1,5,5,5,2,1,3,1,1,2,2,2,2,1,1,2,1,5,1,2,1,2,5,5,2,1,1,4,2,1,4,2,1,1,1,4,2,5,1,5,1,1,3,1,4,3,1,3,2,1,3,1,4,1,2,1,5,1,2,1,4,4,1,3,1,1,1,1,1,5,2,1,5,5,5,3,3,1,2,4,3,2,2,2,2,2,4,3,4,4,4,1,2,2,3,1,1,4,1,1,1,2,1,4,2,1,2,1,1,2,1,5,1,1,3,1,4,3,2,1,1,1,5,4,1,2,5,2,2,1,1,1,1,2,3,3,2,5,1,2,1,2,3,4,3,2,1,1,2,4,3,3,1,1,2,5,1,3,3,4,2,3,1,2,1,4,3,2,2,1,1,2,1,4,2,4,1,4,1,4,4,1,4,4,5,4,1,1,1,3,1,1,1,4,3,5,1,1,1,3,4,1,1,4,3,1,4,1,1,5,1,2,2,5,5,2,1,5 \ No newline at end of file diff --git a/aoc2021/input/test06.in b/aoc2021/input/test06.in new file mode 100644 index 0000000..72bfd5d --- /dev/null +++ b/aoc2021/input/test06.in @@ -0,0 +1 @@ +3,4,3,1,2 \ No newline at end of file