Skip to content

Instantly share code, notes, and snippets.

@albertein
Created December 8, 2021 17:40
Show Gist options
  • Save albertein/4afe9a343dbcd52775b200a38883b53e to your computer and use it in GitHub Desktop.
Save albertein/4afe9a343dbcd52775b200a38883b53e to your computer and use it in GitHub Desktop.
def simulate(lanternfish, days):
new_lanternfish = [0] * 9
for i in range(days):
new_hatched = lanternfish[8]
for i in range(1, 9):
new_lanternfish[i] = lanternfish[i - 1]
new_lanternfish[0] = new_hatched
new_lanternfish[2] += new_hatched
tmp = lanternfish
lanternfish = new_lanternfish
new_lanternfish = tmp
return sum(lanternfish)
if __name__ == '__main__':
with open('input.txt') as data:
initial_input = data.readline().strip()
lanternfish = [0] * 9
for datum in initial_input.split(','):
age = int(datum)
lanternfish[8 - age] += 1
print(simulate(lanternfish, 256))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment