mirror of
https://github.com/thib8956/advent-of-code.git
synced 2025-08-24 16:31:58 +00:00
import 2021
This commit is contained in:
26
2021/day6/day6.py
Normal file
26
2021/day6/day6.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from collections import defaultdict, Counter
|
||||
|
||||
def calculate_fishes(inp, days):
|
||||
fishes = Counter(inp)
|
||||
for day in range(days):
|
||||
fishes_new = defaultdict(int)
|
||||
for fish, cnt in fishes.items():
|
||||
if fish == 0:
|
||||
fishes_new[8] += cnt
|
||||
fishes_new[6] += cnt
|
||||
else:
|
||||
fishes_new[fish - 1] += cnt
|
||||
fishes = fishes_new
|
||||
return sum(fishes.values())
|
||||
|
||||
|
||||
def main(infile):
|
||||
with open(infile) as f:
|
||||
inp = [int(x) for x in f.readline().split(",")]
|
||||
res = calculate_fishes(inp, 80)
|
||||
print(f"Part 1, {res}")
|
||||
res = calculate_fishes(inp, 256)
|
||||
print(f"Part 2, {res}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main("input.txt")
|
Reference in New Issue
Block a user