From: Maximilian Friedersdorff Date: Mon, 6 Dec 2021 22:18:36 +0000 (+0000) Subject: Do the fishes X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=081d73d2bb77101d614400ed76212a4933a64217;hp=122d1c3710447dcf5ea84a0f77497cb066f04544;p=max%2Fadvent_of_code_2021.git Do the fishes --- 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()))