diff --git a/day23/tests/__init__.py b/day23/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/day24/__init__.py b/day24/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/day24/day24.py b/day24/day24.py new file mode 100644 index 0000000..be932b5 --- /dev/null +++ b/day24/day24.py @@ -0,0 +1,2 @@ +INPUT = "day24/input.txt" +INPUT_SMALL = "day24/input-small.txt" diff --git a/day24/input-small.txt b/day24/input-small.txt new file mode 100644 index 0000000..cbe1492 --- /dev/null +++ b/day24/input-small.txt @@ -0,0 +1,5 @@ +19, 13, 30 @ -2, 1, -2 +18, 19, 22 @ -1, -1, -2 +20, 25, 34 @ -2, -2, -4 +12, 31, 28 @ -1, -2, -1 +20, 19, 15 @ 1, -5, -3 \ No newline at end of file diff --git a/day24/lib/__init__.py b/day24/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/day24/lib/classes.py b/day24/lib/classes.py new file mode 100644 index 0000000..24c5419 --- /dev/null +++ b/day24/lib/classes.py @@ -0,0 +1,14 @@ +from dataclasses import dataclass + + +@dataclass(frozen=True) +class Vector3: + x: int + y: int + z: int + + +@dataclass(frozen=True) +class Hailstone: + position: Vector3 + trajectory: Vector3 diff --git a/day24/lib/parsers.py b/day24/lib/parsers.py new file mode 100644 index 0000000..e45f9fa --- /dev/null +++ b/day24/lib/parsers.py @@ -0,0 +1,18 @@ +from day24.lib.classes import Hailstone, Vector3 + + +def parse_vector3(line: str) -> Vector3: + line = line.strip() + x, y, z = line.split(",") + return Vector3(int(x), int(y), int(z)) + + +def parse_input(filename: str) -> list[Hailstone]: + result: list[Hailstone] = [] + with open(filename, "r", encoding="utf8") as file: + for line in file: + line = line.strip() + left, right = line.split("@") + pos, velocity = parse_vector3(left), parse_vector3(right) + result.append(Hailstone(pos, velocity)) + return result diff --git a/day24/tests/__init__.py b/day24/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/day24/tests/test_parsers.py b/day24/tests/test_parsers.py new file mode 100644 index 0000000..65a074b --- /dev/null +++ b/day24/tests/test_parsers.py @@ -0,0 +1,26 @@ +from day24.day24 import INPUT_SMALL +from day24.lib.classes import Hailstone, Vector3 +from day24.lib.parsers import parse_input, parse_vector3 + + +def test_vector3() -> None: + v1: Vector3 = parse_vector3(" 2, 4, 8") + assert v1.x == 2 + assert v1.y == 4 + assert v1.z == 8 + + v2: Vector3 = parse_vector3("3,5,-107") + assert v2.x == 3 + assert v2.y == 5 + assert v2.z == -107 + + +def test_parser() -> None: + hailstones: list[Hailstone] = parse_input(INPUT_SMALL) + + assert len(hailstones) == 5 + assert hailstones[0].position == Vector3(19, 13, 30) + assert hailstones[0].trajectory == Vector3(-2, 1, -2) + + assert hailstones[-1].position == Vector3(20, 19, 15) + assert hailstones[-1].trajectory == Vector3(1, -5, -3)