From 603fb558d957201754cc3e64004f83e2f9ff4745 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 11 Dec 2022 22:48:48 +0100 Subject: Add 2022 day 9 solutions --- 2022/09/.gitignore | 1 + 2022/09/Makefile | 1 + 2022/09/input | 2000 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2022/09/puzzles.py | 68 ++ 4 files changed, 2070 insertions(+) create mode 100644 2022/09/.gitignore create mode 100644 2022/09/Makefile create mode 100644 2022/09/input create mode 100644 2022/09/puzzles.py diff --git a/2022/09/.gitignore b/2022/09/.gitignore new file mode 100644 index 0000000..ffc46fe --- /dev/null +++ b/2022/09/.gitignore @@ -0,0 +1 @@ +puzzle-[12].py diff --git a/2022/09/Makefile b/2022/09/Makefile new file mode 100644 index 0000000..0a4e980 --- /dev/null +++ b/2022/09/Makefile @@ -0,0 +1 @@ +include ../../Makefiles/py.mk diff --git a/2022/09/input b/2022/09/input new file mode 100644 index 0000000..b87df75 --- /dev/null +++ b/2022/09/input @@ -0,0 +1,2000 @@ +U 1 +D 2 +U 1 +L 1 +R 1 +L 1 +D 1 +L 2 +U 2 +L 2 +D 2 +L 2 +D 2 +L 1 +R 1 +D 1 +U 1 +D 1 +R 1 +U 2 +D 2 +R 2 +L 2 +R 2 +D 2 +L 2 +D 2 +R 1 +L 2 +D 2 +R 2 +D 1 +R 1 +L 1 +D 1 +U 1 +L 2 +D 2 +R 1 +L 2 +R 1 +U 1 +R 1 +L 1 +R 2 +D 1 +U 1 +D 1 +R 1 +U 2 +R 2 +D 1 +R 2 +D 1 +U 1 +D 1 +R 2 +U 2 +D 1 +U 2 +D 1 +L 1 +D 1 +U 2 +R 1 +L 1 +R 1 +D 2 +U 1 +D 2 +L 1 +R 2 +U 2 +R 1 +D 1 +R 1 +U 1 +R 1 +U 2 +R 2 +L 1 +U 1 +D 2 +U 1 +D 2 +L 2 +D 1 +U 2 +L 1 +U 1 +D 1 +U 1 +L 1 +D 2 +L 2 +R 1 +D 1 +L 2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D 12 +L 3 +U 3 +L 16 +R 2 +U 14 +R 1 +L 14 +U 11 +L 7 +D 11 +R 2 +D 2 +L 6 +U 10 +L 10 +D 15 +R 12 +D 16 +L 3 +U 15 +R 15 +D 17 +U 17 +L 13 +R 5 +D 12 +L 9 +R 10 +D 4 +L 2 +D 14 +U 8 +R 6 +U 5 +D 1 +L 11 +R 12 +L 17 +U 2 +L 17 +D 2 +R 17 +L 17 +U 3 +D 14 +U 8 +L 14 +D 12 +R 17 +L 18 +D 3 +U 10 +L 7 +U 10 +R 5 +L 15 +D 10 +L 3 +R 12 +D 10 +U 6 +L 17 +D 9 +U 18 +R 7 +U 1 +D 1 +L 9 +U 2 +L 5 +U 9 +L 8 +U 17 +D 17 +L 17 +D 15 +R 13 +U 15 +D 8 +R 13 +D 17 +L 18 +R 5 +D 7 +R 6 +D 1 +R 3 +L 10 +U 10 +D 12 +L 8 +R 11 +U 6 +R 5 +L 9 +R 6 +U 15 +D 4 +R 8 +U 1 +R 18 +L 18 +U 10 +R 17 +D 10 +R 10 +U 16 +R 16 +U 5 +R 7 +D 15 +U 15 +R 2 +U 17 +L 14 +R 1 +U 2 +L 10 +R 17 +L 14 +U 13 +D 1 +L 16 +D 4 +U 9 +L 17 +U 9 +D 9 +L 18 +D 9 +U 5 +L 18 +U 6 +L 5 +U 10 +L 18 +D 13 +R 8 +L 17 +U 9 +L 14 +D 12 +U 2 +D 5 +U 2 +D 17 +L 18 +R 8 +L 7 +R 1 +D 13 +R 11 +D 10 +R 18 +D 2 +U 17 +D 17 +L 4 +R 16 +D 16 +L 2 +D 5 +R 4 +U 9 +R 6 +D 7 +L 13 +U 19 +R 7 +U 17 +L 9 +U 6 +D 1 +L 19 +U 7 +R 6 +L 11 +R 12 +D 6 +L 17 +R 18 +D 17 +L 2 +D 8 +U 15 +D 13 +L 10 +D 10 +L 17 +D 4 +L 12 +U 11 +L 3 +D 6 +U 18 +R 18 +U 16 +L 5 +D 9 +R 17 +L 17 +D 16 +R 12 +D 18 +U 14 +R 1 +U 12 +R 4 +L 6 +U 14 +R 18 +D 6 +U 2 +D 13 +U 15 +L 14 +R 3 +D 7 +L 6 +D 15 +U 17 +L 12 +D 2 +L 12 +R 10 +L 16 +D 15 +L 18 +U 9 +L 7 +U 13 +R 11 +U 9 +L 4 +U 12 +R 14 +D 11 +R 8 +U 4 +L 17 +R 14 +D 15 +R 1 +U 5 +R 3 +L 4 +R 9 +U 1 +D 10 +R 3 +U 16 +D 6 +L 1 +U 15 +D 9 +U 10 +L 11 +U 7 +L 5 +D 19 +L 8 +U 10 +L 19 diff --git a/2022/09/puzzles.py b/2022/09/puzzles.py new file mode 100644 index 0000000..565a39c --- /dev/null +++ b/2022/09/puzzles.py @@ -0,0 +1,68 @@ +#!/usr/bin/python3 + +# START PART 1 +SEGMENTS = 2 +# END PART 1 START PART 2 +SEGMENTS = 10 +# END PART 2 + +position = tuple[int, int] + + +class Segment: + def __init__(self): + self.x = 0 + self.y = 0 + + def track(self, pos: position) -> None: + x, y = pos + dx = x - self.x + dy = y - self.y + nx = 1 if dx > 0 else -1 + ny = 1 if dy > 0 else -1 + + match (abs(dx), abs(dy)): + case (2, 0): + self.x += nx + case (0, 2): + self.y += ny + case (2, 1) | (2, 2) | (1, 2): + self.x += nx + self.y += ny + + @property + def pos(self) -> position: + return self.x, self.y + + +def main() -> None: + with open("input", "r") as f: + data = [(xs[0], int(xs[1])) for xs in [l.split() for l in f.readlines()]] + + snake = [Segment() for _ in range(SEGMENTS)] + head = snake[0] + tail = snake[-1] + locs: set[position] = set() + + for d, c in data: + for _ in range(c): + match d: + case "U": + head.y += 1 + case "D": + head.y -= 1 + case "R": + head.x += 1 + case "L": + head.x -= 1 + + for i, segment in enumerate(snake[1:]): + segment.track(snake[i].pos) + + locs.add(tail.pos) + + print(len(locs)) + + +if __name__ == "__main__": + main() -- cgit v1.2.3