diff --git a/py/aoc/__init__.py b/py/aoc/__init__.py index 9f19f4b..db133a6 100644 --- a/py/aoc/__init__.py +++ b/py/aoc/__init__.py @@ -2,7 +2,11 @@ import sys import argparse from pathlib import Path -DAYS = {} +from .y2022 import d04 + +DAYS = { + "2022_04": y2022.d04.solve, +} def main(): diff --git a/py/aoc/y2022/d04.py b/py/aoc/y2022/d04.py new file mode 100644 index 0000000..4ff92f5 --- /dev/null +++ b/py/aoc/y2022/d04.py @@ -0,0 +1,13 @@ +def solve(inputstr): + part1 = 0 + part2 = 0 + for line in inputstr.splitlines(): + elf1, elf2 = line.split(",") + s1, e1 = map(int, elf1.split("-")) + s2, e2 = map(int, elf2.split("-")) + if s1 <= s2 <= e2 <= e1 or s2 <= s1 <= e1 <= e2: + part1 += 1 + if s1 <= e2 and s2 <= e1: + part2 += 1 + print(f"Part 1: {part1}") + print(f"Part 2: {part2}")