Add 2021/day6
This commit is contained in:
parent
2d3af9d1eb
commit
74a9f60b12
|
@ -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
|
|
@ -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()
|
|
@ -0,0 +1 @@
|
||||||
|
3,4,3,1,2
|
Loading…
Reference in New Issue