diff --git a/2021/d6.py b/2021/d6.py new file mode 100644 index 0000000..6207b94 --- /dev/null +++ b/2021/d6.py @@ -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) diff --git a/README.md b/README.md index bede23a..4c26602 100644 --- a/README.md +++ b/README.md @@ -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