Solve 2021 day 6

This commit is contained in:
felixm 2024-11-17 06:11:54 -05:00
parent 074a7c4458
commit 11bcbce099
2 changed files with 34 additions and 1 deletions

32
2021/d6.py Normal file
View File

@ -0,0 +1,32 @@
from lib import get_data
from lib import ints
from collections import defaultdict
data = get_data(__file__).strip()
xs = ints(data)
for _ in range(80):
for i in range(len(xs)):
if xs[i] == 0:
xs[i] = 6
xs.append(8)
else:
xs[i] -= 1
print(len(xs))
xs = ints(data)
fish = defaultdict(int)
for x in xs:
fish[x] += 1
for _ in range(256):
new_fish = defaultdict(int)
new_fish[8] = fish[0]
new_fish[6] = fish[0]
for i in range(1, 9):
new_fish[i - 1] += fish[i]
fish = new_fish
r = sum(fish.values())
print(r)

View File

@ -177,7 +177,8 @@ Solutions and utility script for Advent of Code challenges in Python.
- Day 3: 23:46 (How long can I take when I try to take long?)
- Day 4: 22:18 (No way. Such stupid bugs.)
- Day 5: 13:30 (Decent, but obviously too slow.)
- Day 6:
- Day 6: 16:33 (Right idea quickly but then struggled to implement.)
- Day 7:
## AoC 2022