]> git.friedersdorff.com Git - max/advent_of_code_2021.git/commitdiff
Do the fishes
authorMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 6 Dec 2021 22:18:36 +0000 (22:18 +0000)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 6 Dec 2021 22:18:36 +0000 (22:18 +0000)
6_1.py [new file with mode: 0644]
6_2.py [new file with mode: 0644]

diff --git a/6_1.py b/6_1.py
new file mode 100644 (file)
index 0000000..accee56
--- /dev/null
+++ b/6_1.py
@@ -0,0 +1,15 @@
+"""Simulate lanternfish pop growth"""
+
+with open("6_input.txt") as f:
+    fishes = [int(x) for x in f.read().split(",")]
+
+for day in range(256):
+    print(day)
+    for i in range(len(fishes)):
+        if fishes[i] == 0:
+            fishes[i] = 6
+            fishes.append(8)
+        else:
+            fishes[i] -= 1
+
+print(len(fishes))
diff --git a/6_2.py b/6_2.py
new file mode 100644 (file)
index 0000000..c4401e8
--- /dev/null
+++ b/6_2.py
@@ -0,0 +1,21 @@
+"""Simulate unreasonably many lanternfish pop growth"""
+
+fishes = {x: 0 for x in range(9)}
+
+with open("6_input.txt") as f:
+    for age in [int(x) for x in f.read().split(",")]:
+        fishes[age] += 1
+
+for day in range(100000):
+    print(day)
+    next_day_fishes = {x: 0 for x in range(9)}
+    next_day_fishes[8] = fishes[0]
+    next_day_fishes[6] = fishes[0]
+
+    for i in range(8):
+        next_day_fishes[i] += fishes[i+1]
+
+    fishes = next_day_fishes
+
+print(fishes)
+print(sum(fishes.values()))