Add day 4, 5, and 6

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2021-12-07 11:15:07 -08:00
parent adb46f38a8
commit c8c3c0dfcd
9 changed files with 1384 additions and 0 deletions

47
day06/day06.py Executable file
View File

@@ -0,0 +1,47 @@
#!/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)

1
day06/example.txt Normal file
View File

@@ -0,0 +1 @@
3,4,3,1,2

1
day06/input.txt Normal file
View File

@@ -0,0 +1 @@
1,3,3,4,5,1,1,1,1,1,1,2,1,4,1,1,1,5,2,2,4,3,1,1,2,5,4,2,2,3,1,2,3,2,1,1,4,4,2,4,4,1,2,4,3,3,3,1,1,3,4,5,2,5,1,2,5,1,1,1,3,2,3,3,1,4,1,1,4,1,4,1,1,1,1,5,4,2,1,2,2,5,5,1,1,1,1,2,1,1,1,1,3,2,3,1,4,3,1,1,3,1,1,1,1,3,3,4,5,1,1,5,4,4,4,4,2,5,1,1,2,5,1,3,4,4,1,4,1,5,5,2,4,5,1,1,3,1,3,1,4,1,3,1,2,2,1,5,1,5,1,3,1,3,1,4,1,4,5,1,4,5,1,1,5,2,2,4,5,1,3,2,4,2,1,1,1,2,1,2,1,3,4,4,2,2,4,2,1,4,1,3,1,3,5,3,1,1,2,2,1,5,2,1,1,1,1,1,5,4,3,5,3,3,1,5,5,4,4,2,1,1,1,2,5,3,3,2,1,1,1,5,5,3,1,4,4,2,4,2,1,1,1,5,1,2,4,1,3,4,4,2,1,4,2,1,3,4,3,3,2,3,1,5,3,1,1,5,1,2,2,4,4,1,2,3,1,2,1,1,2,1,1,1,2,3,5,5,1,2,3,1,3,5,4,2,1,3,3,4