diff options
author | j-james | 2021-12-06 05:39:54 +0000 |
---|---|---|
committer | j-james | 2021-12-06 05:39:54 +0000 |
commit | 851db644dfab429a104188450f016f5d83d9337c (patch) | |
tree | 2e2f36fa5e3115f5d0273229dbb53bcf021d04ba /2021 | |
parent | 4998c58a68c71101e63133bb5501b28be72093c7 (diff) |
Day Six
Diffstat (limited to '2021')
-rw-r--r-- | 2021/06.py | 32 | ||||
-rw-r--r-- | 2021/input/06.txt | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/2021/06.py b/2021/06.py new file mode 100644 index 0000000..654e6b2 --- /dev/null +++ b/2021/06.py @@ -0,0 +1,32 @@ +# Day Six: Lanternfish + +file = open("input/06.txt").readlines() + +ages = [] +for num in file[0].split(","): + ages.append(int(num)) + +for day in range(80): + for i, fish in enumerate(ages): + if fish == 0: + ages[i] = 6 + ages.append(9) + else: + ages[i] = fish-1 +print(len(ages)) + +# ages: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 +ages = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] +for num in file[0].split(","): + ages[int(num)] += 1 + +for day in range(256): + for i, age in enumerate(ages): + if i == 0: + ages[7] += ages[0] + ages[9] += ages[0] + ages[0] -= ages[0] + else: + ages[i-1] += ages[i] + ages[i] -= ages[i] +print(sum(ages)) diff --git a/2021/input/06.txt b/2021/input/06.txt new file mode 100644 index 0000000..936e7a7 --- /dev/null +++ b/2021/input/06.txt @@ -0,0 +1 @@ +1,2,4,5,5,5,2,1,3,1,4,3,2,1,5,5,1,2,3,4,4,1,2,3,2,1,4,4,1,5,5,1,3,4,4,4,1,2,2,5,1,5,5,3,2,3,1,1,3,5,1,1,2,4,2,3,1,1,2,1,3,1,2,1,1,2,1,2,2,1,1,1,1,5,4,5,2,1,3,2,4,1,1,3,4,1,4,1,5,1,4,1,5,3,2,3,2,2,4,4,3,3,4,3,4,4,3,4,5,1,2,5,2,1,5,5,1,3,4,2,2,4,2,2,1,3,2,5,5,1,3,3,4,3,5,3,5,5,4,5,1,1,4,1,4,5,1,1,1,4,1,1,4,2,1,4,1,3,4,4,3,1,2,2,4,3,3,2,2,2,3,5,5,2,3,1,5,1,1,1,1,3,1,4,1,4,1,2,5,3,2,4,4,1,3,1,1,1,3,4,4,1,1,2,1,4,3,4,2,2,3,2,4,3,1,5,1,3,1,4,5,5,3,5,1,3,5,5,4,2,3,2,4,1,3,2,2,2,1,3,4,2,5,2,5,3,5,5,1,1,1,2,2,3,1,4,4,4,5,4,5,5,1,4,5,5,4,1,1,5,3,3,1,4,1,3,1,1,4,1,5,2,3,2,3,1,2,2,2,1,1,5,1,4,5,2,4,2,2,3 |