From 081d73d2bb77101d614400ed76212a4933a64217 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Mon, 6 Dec 2021 22:18:36 +0000 Subject: [PATCH] Do the fishes --- 6_1.py | 15 +++++++++++++++ 6_2.py | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 6_1.py create mode 100644 6_2.py diff --git a/6_1.py b/6_1.py new file mode 100644 index 0000000..accee56 --- /dev/null +++ b/6_1.py @@ -0,0 +1,15 @@ +"""Simulate lanternfish pop growth""" + +with open("6_input.txt") as f: + fishes = [int(x) for x in f.read().split(",")] + +for day in range(256): + print(day) + for i in range(len(fishes)): + if fishes[i] == 0: + fishes[i] = 6 + fishes.append(8) + else: + fishes[i] -= 1 + +print(len(fishes)) diff --git a/6_2.py b/6_2.py new file mode 100644 index 0000000..c4401e8 --- /dev/null +++ b/6_2.py @@ -0,0 +1,21 @@ +"""Simulate unreasonably many lanternfish pop growth""" + +fishes = {x: 0 for x in range(9)} + +with open("6_input.txt") as f: + for age in [int(x) for x in f.read().split(",")]: + fishes[age] += 1 + +for day in range(100000): + print(day) + next_day_fishes = {x: 0 for x in range(9)} + next_day_fishes[8] = fishes[0] + next_day_fishes[6] = fishes[0] + + for i in range(8): + next_day_fishes[i] += fishes[i+1] + + fishes = next_day_fishes + +print(fishes) +print(sum(fishes.values())) -- 2.45.2