From 851db644dfab429a104188450f016f5d83d9337c Mon Sep 17 00:00:00 2001 From: j-james Date: Sun, 5 Dec 2021 21:39:54 -0800 Subject: Day Six --- 2021/06.py | 32 ++++++++++++++++++++++++++++++++ 2021/input/06.txt | 1 + 2 files changed, 33 insertions(+) create mode 100644 2021/06.py create mode 100644 2021/input/06.txt (limited to '2021') 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 -- cgit v1.2.3-70-g09d2