All checks were successful
continuous-integration/drone/push Build is passing
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
#!/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)
|