Created
April 30, 2022 20:12
-
-
Save Mu-adventofcode/176160e71d01b8887d7b7908a95f151c to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 06 part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VALID_DAYS = range(9) | |
def parse_input(filename): | |
with open(filename) as txt: | |
textline = txt.readline().strip() | |
fishes = [int(days) for days in textline.split(",")] | |
return [fishes.count(d) for d in VALID_DAYS] | |
def main(filename, days=80): | |
counts = parse_input(filename) | |
for _ in range(days): | |
spawners = counts[0] | |
counts = counts[1:] | |
counts.append(spawners) # each spawner produces one offspring | |
counts[6] += spawners | |
return sum(counts) | |
if __name__ == "__main__": | |
print(main("input.txt", 256)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment