Created
December 8, 2021 17:40
-
-
Save albertein/4afe9a343dbcd52775b200a38883b53e to your computer and use it in GitHub Desktop.
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 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