Skip to content

Instantly share code, notes, and snippets.

@Mu-adventofcode
Created April 30, 2022 20:12
Show Gist options
  • Save Mu-adventofcode/e4c710c65ff2b26cdbe6b4c4c7b91a13 to your computer and use it in GitHub Desktop.
Save Mu-adventofcode/e4c710c65ff2b26cdbe6b4c4c7b91a13 to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 06 part 1
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