Created
April 30, 2022 20:12
-
-
Save Mu-adventofcode/e4c710c65ff2b26cdbe6b4c4c7b91a13 to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 06 part 1
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
def parse_input(filename): | |
with open(filename) as txt: | |
string = txt.read().strip() | |
return [int(s) for s in string.split(",")] | |
def main(filename, days=80): | |
fishes = parse_input(filename) | |
for _ in range(days): | |
newborns = [8 for fish in fishes if fish == 0] | |
elders = [6 if fish == 0 else fish - 1 for fish in fishes] | |
fishes = elders + newborns | |
return len(fishes) | |
if __name__ == "__main__": | |
print(main("input.txt")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment