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

35 lines
875 B
Python

#!/usr/bin/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[0]
count = [count[i+1] for i in range(8)]
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[0]
count = [count[i+1] for i in range(8)]
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)