This commit is contained in:
48
day-06/day-06.py
Normal file
48
day-06/day-06.py
Normal 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)
|
||||||
1
day-06/input.txt
Normal file
1
day-06/input.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
4,1,1,4,1,1,1,1,1,1,1,1,3,4,1,1,1,3,1,3,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,5,1,2,1,1,5,3,4,2,1,1,4,1,1,5,1,1,5,5,1,1,5,2,1,4,1,2,1,4,5,4,1,1,1,1,3,1,1,1,4,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,2,1,1,1,1,1,1,1,2,4,4,1,1,3,1,3,2,4,3,1,1,1,1,1,2,1,1,1,1,2,5,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,4,1,5,1,3,1,1,1,1,1,5,1,1,1,3,1,2,1,2,1,3,4,5,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,3,1,1,3,1,1,4,1,1,1,1,1,2,1,1,1,1,3,2,1,1,1,4,2,1,1,1,4,1,1,2,3,1,4,1,5,1,1,1,2,1,5,3,3,3,1,5,3,1,1,1,1,1,1,1,1,4,5,3,1,1,5,1,1,1,4,1,1,5,1,2,3,4,2,1,5,2,1,2,5,1,1,1,1,4,1,2,1,1,1,2,5,1,1,5,1,1,1,3,2,4,1,3,1,1,2,1,5,1,3,4,4,2,2,1,1,1,1,5,1,5,2
|
||||||
Reference in New Issue
Block a user