Files
advent-of-code-2021/day-06/day-06.py
Pascal Lais c408a267a6
All checks were successful
continuous-integration/drone/push Build is passing
Update day 6 solution
2021-12-06 07:58:40 +01:00

33 lines
793 B
Python

#!/usr/bin/env python3
from pathlib import Path
def part_1(input):
numbers = [int(n) for n in input[0].split(',')]
count = [len([x for x in numbers if x == i]) for i in range(9)]
for _ in range(80):
tmp = count.pop(0)
count[6] += tmp
count.append(tmp)
result = sum(count)
print("Part 1 result:", result)
def part_2(input):
numbers = [int(n) for n in input[0].split(',')]
count = [len([x for x in numbers if x == i]) for i in range(9)]
for _ in range(256):
tmp = count.pop(0)
count[6] += tmp
count.append(tmp)
result = sum(count)
print("Part 2 result:", result)
input = list()
p = Path(__file__).with_name('input.txt')
with open(p) as f:
input = f.readlines()
part_1(input)
part_2(input)