Initial commit with days 1, 2, and 3

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2021-12-03 12:36:35 -08:00
commit adb46f38a8
8 changed files with 4326 additions and 0 deletions

32
day01/day01.py Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python3
import sys
from typing import Sequence
def part1(lines: Sequence[int]):
inc = 0
last = lines[0]
for line in lines[1:]:
if line > last:
inc += 1
last = line
print(f"{inc} increments")
def part2(lines: Sequence[int]):
WINDOW_SIZE = 3
last = sum(lines[0:WINDOW_SIZE])
inc = 0
for i in range(1, len(lines) - WINDOW_SIZE + 1):
window = sum(lines[i:i+WINDOW_SIZE])
if window > last:
inc += 1
last = window
print(f"{inc} increments")
lines = [int(line) for line in sys.stdin if line]
print("Part 1")
part1(lines)
print("Part 2")
part2(lines)