summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--6.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/6.py b/6.py
index b290710..2d189de 100644
--- a/6.py
+++ b/6.py
@@ -1,12 +1,15 @@
-from functools import cache
+from collections import Counter, deque
from utils import open_day
fish = list(map(int, open_day(6).read().split(',')))
-@cache
-def count_fish(life):
- if life < 0: return 1
- return count_fish(life - 7) + count_fish(life - 9)
+def solve(fish, life):
+ d = deque(Counter(fish)[i] for i in range(9))
+ for i in range(life):
+ zeros = d.popleft()
+ d[6] += zeros
+ d.append(zeros)
+ return sum(d)
-print(sum(count_fish(79 - f) for f in fish))
-print(sum(count_fish(255 - f) for f in fish))
+print(solve(fish, 80))
+print(solve(fish, 256))