summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-06 05:27:02 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-06 05:27:02 +0000
commit394d719a211a58c12ce802aab870c884bc6d1ca7 (patch)
tree09351be4e2b5478eb953d24cc6430cd3d4a72627
parentce5768a2f6e1d70545136d181a721ffe55508b12 (diff)
downloadaoc2021-394d719a211a58c12ce802aab870c884bc6d1ca7.tar.gz
aoc2021-394d719a211a58c12ce802aab870c884bc6d1ca7.tar.xz
aoc2021-394d719a211a58c12ce802aab870c884bc6d1ca7.zip
day 6
-rw-r--r--6.in1
-rw-r--r--6.py16
2 files changed, 17 insertions, 0 deletions
diff --git a/6.in b/6.in
new file mode 100644
index 0000000..de918c7
--- /dev/null
+++ b/6.in
@@ -0,0 +1 @@
+1,1,3,5,1,1,1,4,1,5,1,1,1,1,1,1,1,3,1,1,1,1,2,5,1,1,1,1,1,2,1,4,1,4,1,1,1,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,3,5,1,1,1,1,4,1,5,4,1,1,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,5,1,1,1,3,4,1,1,1,1,3,1,1,1,1,1,4,1,1,3,1,1,3,1,1,1,1,1,3,1,5,2,3,1,2,3,1,1,2,1,2,4,5,1,5,1,4,1,1,1,1,2,1,5,1,1,1,1,1,5,1,1,3,1,1,1,1,1,1,4,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,1,1,1,1,2,2,1,2,1,1,1,5,5,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,5,1,1,1,1,1,1,1,1,3,1,1,3,3,1,1,1,3,5,1,1,4,1,1,1,1,1,4,1,1,3,1,1,1,1,1,1,1,1,2,1,5,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1
diff --git a/6.py b/6.py
new file mode 100644
index 0000000..4e1e127
--- /dev/null
+++ b/6.py
@@ -0,0 +1,16 @@
+from functools import cache
+from utils import open_day
+
+fish = list(map(int, open_day(6).read().split(',')))
+
+@cache
+def count_fish(n, life):
+ if life < 0:
+ return 1
+ if n == 0:
+ return count_fish(0, life - 7) + count_fish(2, life - 7)
+ else:
+ return count_fish(0, life - n)
+
+print(sum(count_fish(f, 79) for f in fish))
+print(sum(count_fish(f, 255) for f in fish))