Add 2021/day6

This commit is contained in:
Roland Thomas Jr 2023-10-03 14:19:08 -04:00
parent 2d3af9d1eb
commit 74a9f60b12
Signed by: roland
GPG Key ID: 7C3C2B085A4C2872
3 changed files with 43 additions and 0 deletions

1
2021/day6 Normal file
View File

@ -0,0 +1 @@
3,5,2,5,4,3,2,2,3,5,2,3,2,2,2,2,3,5,3,5,5,2,2,3,4,2,3,5,5,3,3,5,2,4,5,4,3,5,3,2,5,4,1,1,1,5,1,4,1,4,3,5,2,3,2,2,2,5,2,1,2,2,2,2,3,4,5,2,5,4,1,3,1,5,5,5,3,5,3,1,5,4,2,5,3,3,5,5,5,3,2,2,1,1,3,2,1,2,2,4,3,4,1,3,4,1,2,2,4,1,3,1,4,3,3,1,2,3,1,3,4,1,1,2,5,1,2,1,2,4,1,3,2,1,1,2,4,3,5,1,3,2,1,3,2,3,4,5,5,4,1,3,4,1,2,3,5,2,3,5,2,1,1,5,5,4,4,4,5,3,3,2,5,4,4,1,5,1,5,5,5,2,2,1,2,4,5,1,2,1,4,5,4,2,4,3,2,5,2,2,1,4,3,5,4,2,1,1,5,1,4,5,1,2,5,5,1,4,1,1,4,5,2,5,3,1,4,5,2,1,3,1,3,3,5,5,1,4,1,3,2,2,3,5,4,3,2,5,1,1,1,2,2,5,3,4,2,1,3,2,5,3,2,2,3,5,2,1,4,5,4,4,5,5,3,3,5,4,5,5,4,3,5,3,5,3,1,3,2,2,1,4,4,5,2,2,4,2,1,4

41
2021/day6.py Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
from sys import argv
from collections import Counter, deque
def attempt_one(line, iterations):
fishes = [int(fish) for fish in line if fish.isdigit()]
for days in range(iterations):
number_zeroes = fishes.count(0)
fishes = [fish if fish else 7 for fish in fishes]
if number_zeroes:
fishes.extend(number_zeroes * [9])
fishes = [fish-1 for fish in fishes]
return len(fishes)
def lanternfish(line, iterations):
fishes = Counter([int(fish) for fish in line if fish.isdigit()])
fishes_list = [0] * 9
for fish in fishes:
fishes_list[fish] = fishes[fish]
fishes_que = deque(fishes_list)
for days in range(iterations):
number_zeroes = fishes_que.popleft()
fishes_que.append(number_zeroes)
fishes_que[6] += number_zeroes
return sum(fishes_que)
def main():
with open("day6", "r") as file:
line = file.readline()
print(lanternfish(line, 80))
print(lanternfish(line, 256))
if __name__ == "__main__":
main()

1
2021/day6.sample Normal file
View File

@ -0,0 +1 @@
3,4,3,1,2