Add day 6 solution
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-12-06 06:29:19 +01:00
parent fe738ad150
commit 85e17564b4
2 changed files with 49 additions and 0 deletions

48
day-06/day-06.py Normal file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/python3
from pathlib import Path
def part_1(input):
result = 0
numbers = input[0].split(',')
numbers = [int(n) for n in numbers]
for i in range(80):
new_numbers = []
new = 0
for n in numbers:
if n > 0:
n -= 1
else:
n = 6
new += 1
new_numbers.append(n)
new_numbers += [8 for x in range(new)]
numbers = new_numbers
result = len(numbers)
print("Part 1 result:", result)
def part_2(input):
result = 0
numbers = input[0].split(',')
numbers = [int(n) for n in numbers]
count = [0] * 9
for i in range(9):
count[i] = len([x for x in numbers if x == i])
for i in range(256):
tmp = count[0]
for j in range(8):
count[j] = count[j+1]
count[8] = tmp
count[6] += tmp
for c in count:
result += c
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)