48 lines
1.1 KiB
Python
Executable File
48 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
from typing import Sequence
|
|
from copy import deepcopy
|
|
|
|
|
|
def part1(fish: Sequence[int], count: int):
|
|
for i in range(count):
|
|
new = []
|
|
for f in fish:
|
|
if f == 0:
|
|
new += [8]
|
|
f = 7
|
|
f -= 1
|
|
new += [f]
|
|
fish = new
|
|
print(len(fish))
|
|
|
|
|
|
def part2(init: Sequence[int], count: int):
|
|
# This is a mapping for the number of fish by index, 0-8
|
|
fish = [0] * 9
|
|
for i in init:
|
|
fish[i] += 1
|
|
# Go through each day, rotating everything to the left
|
|
for _ in range(count):
|
|
zeroes = fish[0]
|
|
# rotate
|
|
for i in range(1, len(fish)):
|
|
fish[i - 1] = fish[i]
|
|
# position 8
|
|
fish[len(fish) - 1] = zeroes
|
|
# position 6
|
|
fish[len(fish) - 3] += zeroes
|
|
print(sum(fish))
|
|
|
|
|
|
fish = [int(state) for state in sys.stdin.readline().strip().split(",") if state]
|
|
|
|
print("Part 1 (80 days)")
|
|
# part1(fish, 80)
|
|
# Part 2 function does the same thing except much faster
|
|
part2(fish, 80)
|
|
print(len(fish))
|
|
|
|
print("Part 2 (256 days)")
|
|
part2(fish, 256)
|