From 03b3b6807143f32c7d369230d3827ac218320a9a Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 5 Dec 2022 18:34:37 +0100 Subject: [PATCH] Start day 5 --- .pre-commit-config.yaml | 1 + 2022/day05_supply_stacks.py | 66 +++++ 2022/inputs/day05 | 514 ++++++++++++++++++++++++++++++++++++ 2022/inputs/day05-test1 | 9 + 4 files changed, 590 insertions(+) create mode 100644 2022/day05_supply_stacks.py create mode 100644 2022/inputs/day05 create mode 100644 2022/inputs/day05-test1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b41b66e..a908441 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,7 @@ repos: - id: trailing-whitespace args: - --markdown-linebreak-ext=md + exclude: ^2022/inputs/day05 - repo: https://github.com/asottile/pyupgrade rev: v3.2.2 hooks: diff --git a/2022/day05_supply_stacks.py b/2022/day05_supply_stacks.py new file mode 100644 index 0000000..4e0464d --- /dev/null +++ b/2022/day05_supply_stacks.py @@ -0,0 +1,66 @@ +from __future__ import annotations + +import dataclasses +import re + + +def main(filename: str, expected_part_1: str = None, expected_part_2: str = None): + print(f"\n+ Running on {filename}") + with open(filename) as f: + data = f.read().rstrip().split("\n\n") + + data = parse_data(data) + solution_part_1 = solve_part_1(data) + + print(f"1. Found {solution_part_1}") + if expected_part_1: + assert expected_part_1 == solution_part_1 + + solution_part_2 = solve_part_2(data) + print(f"2. Found {solution_part_2}") + if expected_part_2: + assert expected_part_2 == solution_part_2 + + +@dataclasses.dataclass +class Instruction: + quantity: int + source: int + destination: int + + @classmethod + def from_text(cls, text) -> Instruction: + match = re.match(r"move (\d) from (\d) to (\d)", text) + quantity, source, destination = match.groups() + return cls(quantity, source, destination) + + +@dataclasses.dataclass +class Game: + stacks: list[list[str]] + instructions: list[Instruction] + + +DataType = Game + + +def parse_data(data: list[str]) -> DataType: + stacks, instructions = data + parsed_instructions = [] + for instruction in instructions.split("\n"): + parsed_instructions.append(Instruction.from_text(instruction)) + print(stacks.split("\n")) + return None + + +def solve_part_1(data: DataType) -> str: + return "0" + + +def solve_part_2(data: DataType) -> str: + return "0" + + +if __name__ == "__main__": + main("inputs/day05-test1", expected_part_1="CMZ") + main("inputs/day05") diff --git a/2022/inputs/day05 b/2022/inputs/day05 new file mode 100644 index 0000000..69594d0 --- /dev/null +++ b/2022/inputs/day05 @@ -0,0 +1,514 @@ + [Q] [P] [P] + [G] [V] [S] [Z] [F] + [W] [V] [F] [Z] [W] [Q] + [V] [T] [N] [J] [W] [B] [W] + [Z] [L] [V] [B] [C] [R] [N] [M] +[C] [W] [R] [H] [H] [P] [T] [M] [B] +[Q] [Q] [M] [Z] [Z] [N] [G] [G] [J] +[B] [R] [B] [C] [D] [H] [D] [C] [N] + 1 2 3 4 5 6 7 8 9 + +move 3 from 6 to 2 +move 5 from 6 to 7 +move 6 from 2 to 5 +move 1 from 9 to 7 +move 1 from 1 to 9 +move 1 from 5 to 3 +move 1 from 2 to 5 +move 3 from 4 to 5 +move 10 from 7 to 3 +move 1 from 4 to 9 +move 6 from 8 to 7 +move 4 from 7 to 8 +move 1 from 7 to 3 +move 1 from 1 to 2 +move 1 from 2 to 8 +move 1 from 9 to 1 +move 3 from 9 to 4 +move 4 from 8 to 3 +move 4 from 7 to 1 +move 4 from 4 to 6 +move 2 from 8 to 7 +move 9 from 3 to 8 +move 2 from 7 to 4 +move 3 from 4 to 9 +move 4 from 1 to 9 +move 4 from 3 to 9 +move 2 from 1 to 4 +move 1 from 4 to 6 +move 3 from 3 to 2 +move 1 from 2 to 8 +move 1 from 2 to 7 +move 3 from 6 to 2 +move 2 from 6 to 7 +move 4 from 2 to 3 +move 3 from 7 to 9 +move 2 from 5 to 6 +move 15 from 9 to 4 +move 4 from 9 to 2 +move 12 from 5 to 4 +move 9 from 8 to 5 +move 25 from 4 to 7 +move 1 from 4 to 7 +move 1 from 4 to 8 +move 2 from 2 to 5 +move 1 from 4 to 2 +move 23 from 7 to 6 +move 2 from 5 to 2 +move 22 from 6 to 8 +move 4 from 5 to 9 +move 1 from 7 to 9 +move 2 from 6 to 4 +move 2 from 4 to 7 +move 25 from 8 to 3 +move 1 from 2 to 1 +move 3 from 2 to 3 +move 1 from 6 to 8 +move 1 from 1 to 8 +move 1 from 2 to 8 +move 1 from 8 to 1 +move 4 from 5 to 7 +move 1 from 8 to 4 +move 5 from 9 to 8 +move 5 from 8 to 9 +move 1 from 8 to 5 +move 3 from 5 to 4 +move 3 from 9 to 1 +move 30 from 3 to 4 +move 3 from 1 to 4 +move 2 from 9 to 5 +move 4 from 7 to 9 +move 16 from 4 to 8 +move 6 from 3 to 9 +move 3 from 7 to 3 +move 19 from 4 to 7 +move 8 from 9 to 4 +move 1 from 1 to 9 +move 13 from 7 to 9 +move 3 from 7 to 8 +move 3 from 5 to 9 +move 4 from 8 to 3 +move 2 from 7 to 3 +move 14 from 9 to 4 +move 10 from 3 to 1 +move 12 from 4 to 8 +move 6 from 1 to 9 +move 1 from 1 to 2 +move 1 from 7 to 1 +move 6 from 9 to 3 +move 17 from 8 to 6 +move 10 from 8 to 5 +move 1 from 7 to 8 +move 1 from 9 to 5 +move 2 from 3 to 1 +move 4 from 5 to 9 +move 1 from 8 to 7 +move 6 from 9 to 7 +move 4 from 4 to 2 +move 3 from 4 to 6 +move 4 from 5 to 9 +move 4 from 9 to 3 +move 1 from 2 to 4 +move 4 from 4 to 7 +move 3 from 5 to 3 +move 1 from 4 to 5 +move 5 from 1 to 2 +move 1 from 1 to 9 +move 7 from 2 to 7 +move 1 from 5 to 7 +move 8 from 3 to 5 +move 20 from 6 to 7 +move 9 from 7 to 9 +move 2 from 2 to 9 +move 2 from 3 to 1 +move 2 from 1 to 3 +move 2 from 3 to 4 +move 2 from 4 to 6 +move 1 from 3 to 9 +move 1 from 4 to 9 +move 1 from 6 to 9 +move 2 from 5 to 8 +move 2 from 8 to 5 +move 1 from 6 to 7 +move 2 from 5 to 8 +move 6 from 9 to 5 +move 2 from 8 to 6 +move 11 from 9 to 2 +move 1 from 6 to 5 +move 11 from 2 to 5 +move 1 from 6 to 4 +move 7 from 5 to 9 +move 7 from 9 to 1 +move 1 from 4 to 9 +move 28 from 7 to 5 +move 1 from 7 to 5 +move 5 from 5 to 9 +move 5 from 9 to 3 +move 6 from 1 to 8 +move 1 from 1 to 7 +move 5 from 3 to 2 +move 1 from 7 to 8 +move 7 from 8 to 1 +move 1 from 9 to 4 +move 2 from 2 to 5 +move 22 from 5 to 3 +move 1 from 7 to 8 +move 1 from 4 to 7 +move 1 from 8 to 9 +move 1 from 9 to 4 +move 14 from 5 to 7 +move 5 from 5 to 9 +move 19 from 3 to 4 +move 1 from 2 to 9 +move 2 from 2 to 5 +move 1 from 5 to 1 +move 6 from 1 to 7 +move 2 from 7 to 6 +move 1 from 1 to 9 +move 2 from 5 to 8 +move 8 from 4 to 5 +move 3 from 4 to 7 +move 3 from 3 to 5 +move 2 from 8 to 9 +move 16 from 7 to 5 +move 9 from 4 to 6 +move 22 from 5 to 3 +move 1 from 5 to 8 +move 1 from 8 to 7 +move 10 from 3 to 4 +move 1 from 5 to 4 +move 10 from 4 to 5 +move 8 from 5 to 2 +move 5 from 2 to 7 +move 5 from 7 to 1 +move 4 from 7 to 6 +move 3 from 9 to 7 +move 2 from 2 to 3 +move 3 from 5 to 1 +move 6 from 9 to 7 +move 5 from 7 to 8 +move 6 from 1 to 5 +move 6 from 3 to 4 +move 4 from 4 to 2 +move 1 from 4 to 6 +move 5 from 8 to 7 +move 3 from 2 to 3 +move 1 from 1 to 4 +move 1 from 1 to 9 +move 2 from 2 to 1 +move 2 from 4 to 3 +move 4 from 3 to 7 +move 3 from 7 to 3 +move 13 from 6 to 1 +move 1 from 9 to 2 +move 6 from 3 to 5 +move 8 from 1 to 4 +move 1 from 2 to 7 +move 9 from 4 to 9 +move 7 from 5 to 1 +move 2 from 5 to 6 +move 1 from 1 to 4 +move 1 from 4 to 3 +move 2 from 1 to 2 +move 5 from 3 to 6 +move 2 from 6 to 1 +move 13 from 7 to 6 +move 2 from 3 to 4 +move 2 from 2 to 9 +move 2 from 7 to 8 +move 6 from 9 to 2 +move 1 from 9 to 3 +move 1 from 5 to 2 +move 7 from 1 to 2 +move 1 from 6 to 7 +move 1 from 4 to 8 +move 1 from 3 to 1 +move 1 from 7 to 8 +move 7 from 1 to 9 +move 4 from 8 to 6 +move 1 from 5 to 3 +move 9 from 9 to 5 +move 1 from 1 to 2 +move 14 from 2 to 7 +move 2 from 9 to 3 +move 13 from 5 to 3 +move 24 from 6 to 9 +move 6 from 3 to 5 +move 14 from 7 to 9 +move 1 from 4 to 1 +move 20 from 9 to 7 +move 9 from 3 to 8 +move 15 from 9 to 6 +move 1 from 5 to 8 +move 1 from 2 to 3 +move 14 from 6 to 3 +move 2 from 3 to 4 +move 2 from 3 to 6 +move 13 from 7 to 1 +move 8 from 3 to 5 +move 1 from 3 to 9 +move 8 from 5 to 4 +move 4 from 5 to 2 +move 10 from 1 to 3 +move 6 from 4 to 5 +move 4 from 5 to 1 +move 3 from 1 to 6 +move 7 from 8 to 2 +move 4 from 4 to 3 +move 13 from 3 to 6 +move 3 from 8 to 1 +move 3 from 7 to 8 +move 3 from 8 to 4 +move 1 from 4 to 2 +move 2 from 3 to 4 +move 1 from 5 to 7 +move 4 from 7 to 1 +move 2 from 3 to 5 +move 3 from 2 to 1 +move 1 from 4 to 7 +move 7 from 2 to 4 +move 2 from 4 to 3 +move 1 from 7 to 5 +move 4 from 9 to 5 +move 1 from 4 to 2 +move 3 from 2 to 9 +move 8 from 1 to 7 +move 1 from 3 to 5 +move 7 from 5 to 7 +move 10 from 6 to 4 +move 1 from 5 to 1 +move 4 from 1 to 3 +move 9 from 7 to 6 +move 3 from 1 to 8 +move 12 from 4 to 6 +move 5 from 4 to 6 +move 2 from 9 to 3 +move 3 from 8 to 7 +move 1 from 1 to 3 +move 3 from 7 to 8 +move 5 from 7 to 5 +move 1 from 7 to 5 +move 2 from 3 to 1 +move 2 from 8 to 7 +move 3 from 5 to 1 +move 1 from 9 to 7 +move 1 from 8 to 3 +move 4 from 7 to 8 +move 4 from 5 to 9 +move 4 from 1 to 7 +move 3 from 8 to 6 +move 1 from 8 to 1 +move 1 from 7 to 1 +move 1 from 5 to 8 +move 1 from 8 to 7 +move 7 from 3 to 1 +move 3 from 9 to 1 +move 1 from 9 to 3 +move 28 from 6 to 3 +move 3 from 7 to 8 +move 2 from 8 to 2 +move 1 from 2 to 7 +move 2 from 6 to 1 +move 18 from 3 to 9 +move 5 from 3 to 4 +move 2 from 7 to 4 +move 2 from 1 to 8 +move 1 from 2 to 6 +move 7 from 6 to 4 +move 4 from 4 to 3 +move 3 from 8 to 1 +move 4 from 9 to 8 +move 1 from 4 to 8 +move 9 from 1 to 6 +move 5 from 1 to 3 +move 4 from 6 to 7 +move 7 from 6 to 3 +move 5 from 8 to 1 +move 12 from 3 to 6 +move 7 from 6 to 4 +move 4 from 3 to 5 +move 5 from 6 to 7 +move 12 from 4 to 3 +move 6 from 1 to 4 +move 4 from 4 to 2 +move 14 from 9 to 8 +move 17 from 3 to 2 +move 5 from 4 to 9 +move 1 from 9 to 6 +move 5 from 2 to 1 +move 1 from 9 to 8 +move 5 from 1 to 6 +move 2 from 2 to 6 +move 12 from 2 to 4 +move 6 from 7 to 2 +move 3 from 7 to 6 +move 3 from 9 to 8 +move 5 from 4 to 7 +move 4 from 2 to 6 +move 3 from 6 to 8 +move 5 from 8 to 2 +move 7 from 6 to 8 +move 1 from 7 to 3 +move 6 from 4 to 3 +move 1 from 8 to 1 +move 1 from 5 to 7 +move 2 from 6 to 8 +move 13 from 8 to 2 +move 3 from 5 to 4 +move 1 from 1 to 2 +move 3 from 6 to 2 +move 1 from 1 to 4 +move 4 from 4 to 8 +move 8 from 3 to 1 +move 2 from 4 to 8 +move 15 from 2 to 4 +move 16 from 8 to 3 +move 1 from 8 to 6 +move 1 from 7 to 2 +move 8 from 1 to 2 +move 1 from 6 to 8 +move 6 from 3 to 1 +move 3 from 3 to 8 +move 6 from 3 to 1 +move 6 from 2 to 9 +move 2 from 1 to 4 +move 1 from 8 to 5 +move 8 from 2 to 9 +move 8 from 1 to 4 +move 3 from 8 to 6 +move 21 from 4 to 7 +move 1 from 9 to 7 +move 2 from 6 to 8 +move 1 from 5 to 1 +move 1 from 3 to 9 +move 8 from 9 to 4 +move 1 from 1 to 7 +move 1 from 1 to 4 +move 1 from 6 to 8 +move 1 from 9 to 3 +move 2 from 9 to 5 +move 2 from 5 to 3 +move 1 from 9 to 4 +move 3 from 8 to 2 +move 1 from 1 to 4 +move 4 from 4 to 9 +move 3 from 3 to 2 +move 5 from 9 to 1 +move 17 from 7 to 1 +move 1 from 9 to 1 +move 2 from 2 to 4 +move 1 from 4 to 2 +move 8 from 2 to 9 +move 5 from 4 to 5 +move 6 from 4 to 8 +move 20 from 1 to 6 +move 2 from 9 to 8 +move 1 from 2 to 9 +move 2 from 8 to 7 +move 8 from 7 to 8 +move 4 from 5 to 9 +move 14 from 8 to 7 +move 1 from 5 to 7 +move 7 from 9 to 1 +move 3 from 6 to 4 +move 3 from 9 to 7 +move 12 from 6 to 7 +move 22 from 7 to 9 +move 2 from 2 to 5 +move 10 from 1 to 7 +move 1 from 4 to 1 +move 2 from 6 to 1 +move 1 from 1 to 3 +move 2 from 4 to 8 +move 2 from 8 to 6 +move 1 from 3 to 8 +move 1 from 4 to 1 +move 2 from 5 to 3 +move 1 from 8 to 4 +move 2 from 3 to 7 +move 19 from 9 to 7 +move 1 from 1 to 4 +move 2 from 9 to 1 +move 2 from 1 to 6 +move 1 from 6 to 5 +move 42 from 7 to 8 +move 1 from 7 to 6 +move 2 from 4 to 8 +move 7 from 6 to 8 +move 2 from 1 to 5 +move 2 from 9 to 5 +move 14 from 8 to 3 +move 22 from 8 to 2 +move 3 from 5 to 6 +move 10 from 8 to 6 +move 5 from 8 to 9 +move 12 from 6 to 7 +move 2 from 5 to 1 +move 5 from 3 to 2 +move 7 from 3 to 5 +move 2 from 5 to 1 +move 2 from 3 to 7 +move 4 from 1 to 2 +move 1 from 5 to 7 +move 1 from 5 to 4 +move 1 from 6 to 2 +move 1 from 9 to 2 +move 9 from 7 to 3 +move 1 from 4 to 1 +move 3 from 7 to 5 +move 4 from 3 to 2 +move 5 from 2 to 3 +move 2 from 5 to 2 +move 34 from 2 to 9 +move 1 from 1 to 5 +move 15 from 9 to 3 +move 2 from 3 to 2 +move 1 from 5 to 4 +move 7 from 3 to 8 +move 3 from 9 to 2 +move 6 from 9 to 4 +move 5 from 9 to 3 +move 4 from 4 to 6 +move 1 from 6 to 8 +move 1 from 3 to 5 +move 6 from 3 to 2 +move 1 from 4 to 9 +move 2 from 4 to 2 +move 4 from 5 to 8 +move 1 from 5 to 6 +move 1 from 7 to 6 +move 1 from 9 to 6 +move 1 from 7 to 2 +move 12 from 8 to 7 +move 2 from 7 to 3 +move 4 from 6 to 9 +move 7 from 9 to 4 +move 9 from 3 to 9 +move 11 from 7 to 4 +move 3 from 9 to 6 +move 1 from 4 to 1 +move 15 from 4 to 3 +move 2 from 4 to 1 +move 3 from 1 to 4 +move 17 from 3 to 7 +move 4 from 3 to 7 +move 7 from 9 to 2 +move 3 from 4 to 1 +move 4 from 6 to 9 +move 1 from 9 to 6 +move 1 from 3 to 1 +move 5 from 7 to 9 +move 8 from 9 to 4 +move 1 from 1 to 6 +move 6 from 4 to 9 +move 4 from 2 to 3 +move 1 from 4 to 3 +move 1 from 4 to 9 +move 1 from 1 to 7 +move 1 from 7 to 9 +move 3 from 6 to 2 +move 9 from 2 to 3 +move 1 from 9 to 4 +move 1 from 1 to 5 +move 12 from 7 to 6 +move 4 from 9 to 8 diff --git a/2022/inputs/day05-test1 b/2022/inputs/day05-test1 new file mode 100644 index 0000000..84933bb --- /dev/null +++ b/2022/inputs/day05-test1 @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2