summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-06 05:37:17 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-06 05:37:17 +0000
commit7d710ad3f92e8e85645b7a68b353d2b853bf111e (patch)
tree06d98e36a2842e7e0646fc8922d77a9ad3befe12
parent394d719a211a58c12ce802aab870c884bc6d1ca7 (diff)
downloadaoc2021-7d710ad3f92e8e85645b7a68b353d2b853bf111e.tar.gz
aoc2021-7d710ad3f92e8e85645b7a68b353d2b853bf111e.tar.xz
aoc2021-7d710ad3f92e8e85645b7a68b353d2b853bf111e.zip
day 6: simplified
-rw-r--r--6.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/6.py b/6.py
index 4e1e127..b290710 100644
--- a/6.py
+++ b/6.py
@@ -4,13 +4,9 @@ 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)
+def count_fish(life):
+ if life < 0: return 1
+ return count_fish(life - 7) + count_fish(life - 9)
-print(sum(count_fish(f, 79) for f in fish))
-print(sum(count_fish(f, 255) for f in fish))
+print(sum(count_fish(79 - f) for f in fish))
+print(sum(count_fish(255 - f) for f in fish))