1
0
Fork 0

formatting and cosmetic updates to 2020.

This commit is contained in:
Gabe Venberg 2026-04-17 16:21:34 +02:00
parent 84c4cf9991
commit cd75e58f77
28 changed files with 320 additions and 287 deletions

View file

@ -2,25 +2,35 @@
import pathlib
import sys
import re
from dataclasses import dataclass
from pprint import pprint
def parse(puzzle_input: str):
"""Parse input"""
# returns a 2 dimentional array where true means there is a tree there.
return [[i=='#' for i in j] for j in puzzle_input.splitlines()]
return [[i == "#" for i in j] for j in puzzle_input.splitlines()]
def part1(data):
"""Solve part 1"""
return solveForSlope(data, 3, 1)
def solveForSlope(data, right: int, down: int):
return sum(1 for index, row in enumerate(data[::down]) if row[(right*index)%len(row)])
return sum(
1 for index, row in enumerate(data[::down]) if row[(right * index) % len(row)]
)
def part2(data):
"""Solve part 2"""
return solveForSlope(data,1,1)*solveForSlope(data,3,1)*solveForSlope(data,5,1)*solveForSlope(data,7,1)*solveForSlope(data,1,2)
return (
solveForSlope(data, 1, 1)
* solveForSlope(data, 3, 1)
* solveForSlope(data, 5, 1)
* solveForSlope(data, 7, 1)
* solveForSlope(data, 1, 2)
)
def solve(puzzle_input):
"""Solve the puzzle for the given input"""
@ -30,6 +40,7 @@ def solve(puzzle_input):
return solution1, solution2
if __name__ == "__main__":
for path in sys.argv[1:]:
print(f"{path}:")