Solve 2021 day 6
This commit is contained in:
32
2021/d6.py
Normal file
32
2021/d6.py
Normal 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)
|
||||||
@@ -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 3: 23:46 (How long can I take when I try to take long?)
|
||||||
- Day 4: 22:18 (No way. Such stupid bugs.)
|
- Day 4: 22:18 (No way. Such stupid bugs.)
|
||||||
- Day 5: 13:30 (Decent, but obviously too slow.)
|
- 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
|
## AoC 2022
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user