about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2021-12-06 00:16:42 -0500
committerBen Harris <ben@tilde.team>2021-12-06 00:16:42 -0500
commit93e61904ac932d63089ac6d0659aef866d2d2e98 (patch)
tree408cb9c7f0d783f0433918e6290932220635bae7
parent7e50cb1a54b3ed99f8081f976bf18ab85202469a (diff)
day 6 part 1
-rw-r--r--aoc2021.test/DayTests.cs1
-rw-r--r--aoc2021/Day06.cs43
-rw-r--r--aoc2021/input/day06.in1
-rw-r--r--aoc2021/input/test06.in1
4 files changed, 46 insertions, 0 deletions
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;
+
+/// <summary>
+/// Day 6: <see href="https://adventofcode.com/2021/day/6"/>
+/// </summary>
+public sealed class Day06 : Day
+{
+    private readonly List<int> _fishes;
+    public Day06() : base(6, "Lanternfish")
+    {
+        //UseTestInput = true;
+        _fishes = Input.First().Split(',').Select(int.Parse).ToList();
+    }
+
+    private static List<int> DayStep(List<int> state)
+    {
+        List<int> 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