diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-02 17:28:01 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-02 17:28:01 +0000 |
commit | 72724bb3a507465b8f1df65eeb6a3bee62549705 (patch) | |
tree | 98f1fed79622f951e48e933a7e59194d4b2b9432 | |
parent | 1f88313cc4ff52f06b5c99ff2364910d8bc10e1d (diff) | |
download | aoc2021-72724bb3a507465b8f1df65eeb6a3bee62549705.tar.gz aoc2021-72724bb3a507465b8f1df65eeb6a3bee62549705.tar.xz aoc2021-72724bb3a507465b8f1df65eeb6a3bee62549705.zip |
day 2
-rw-r--r-- | 2.in | 1000 | ||||
-rw-r--r-- | 2.py | 28 |
2 files changed, 1028 insertions, 0 deletions
@@ -0,0 +1,1000 @@ +forward 2 +down 8 +down 1 +up 7 +forward 4 +down 4 +down 3 +forward 2 +forward 5 +forward 2 +forward 7 +forward 8 +down 7 +forward 6 +forward 1 +down 8 +down 8 +up 9 +down 9 +forward 1 +up 1 +forward 6 +forward 7 +down 7 +forward 4 +forward 2 +forward 1 +forward 3 +forward 8 +forward 4 +up 6 +down 2 +forward 4 +down 3 +up 3 +up 2 +up 3 +forward 8 +down 5 +down 8 +down 5 +down 4 +down 2 +up 1 +forward 6 +forward 6 +forward 8 +up 5 +down 5 +forward 8 +forward 7 +down 9 +down 7 +down 6 +down 3 +forward 3 +up 7 +forward 2 +up 6 +forward 7 +forward 9 +down 9 +forward 3 +down 2 +down 2 +down 7 +down 7 +forward 8 +down 7 +forward 9 +up 7 +down 4 +down 8 +forward 2 +forward 2 +up 1 +forward 8 +down 5 +forward 8 +forward 4 +up 1 +forward 2 +forward 2 +forward 2 +down 9 +down 7 +down 9 +forward 9 +forward 4 +up 7 +down 4 +forward 9 +forward 8 +up 5 +up 1 +down 1 +down 9 +down 6 +up 8 +forward 2 +forward 7 +up 7 +forward 7 +forward 6 +down 6 +forward 8 +up 6 +forward 7 +down 7 +forward 4 +forward 9 +up 9 +up 8 +forward 8 +forward 3 +up 1 +up 4 +down 4 +up 9 +up 8 +forward 6 +down 2 +down 2 +up 4 +forward 4 +forward 1 +down 8 +forward 6 +down 5 +forward 6 +down 8 +up 1 +forward 1 +up 9 +down 8 +up 3 +up 9 +forward 9 +forward 2 +down 2 +up 6 +up 6 +forward 8 +up 3 +down 3 +forward 5 +up 2 +forward 1 +forward 1 +forward 8 +down 4 +forward 8 +forward 7 +down 8 +forward 7 +down 7 +down 2 +down 1 +down 7 +up 9 +down 5 +up 1 +forward 7 +down 5 +down 9 +down 2 +down 8 +down 4 +forward 2 +forward 2 +forward 1 +down 6 +up 7 +forward 2 +down 1 +down 5 +forward 3 +forward 8 +down 4 +up 2 +up 9 +up 7 +forward 7 +forward 4 +up 8 +up 3 +up 4 +forward 6 +down 7 +forward 7 +up 6 +down 9 +up 6 +forward 4 +up 3 +down 3 +up 6 +down 9 +down 6 +forward 7 +forward 9 +forward 2 +down 6 +up 3 +up 9 +forward 9 +forward 8 +up 4 +up 5 +forward 6 +down 5 +up 4 +up 9 +down 8 +forward 5 +up 5 +forward 7 +forward 6 +down 8 +down 5 +down 2 +up 5 +down 8 +forward 7 +forward 7 +up 6 +forward 3 +down 8 +forward 5 +forward 8 +down 7 +forward 6 +down 2 +forward 2 +forward 8 +down 4 +forward 5 +forward 7 +forward 5 +forward 8 +forward 9 +forward 6 +down 6 +up 7 +down 9 +forward 7 +forward 1 +up 2 +forward 8 +down 1 +up 9 +forward 7 +down 2 +up 2 +forward 5 +down 4 +down 3 +up 8 +up 6 +forward 3 +up 4 +forward 3 +forward 1 +forward 1 +up 9 +down 2 +down 9 +up 4 +forward 4 +forward 4 +forward 2 +forward 5 +forward 9 +forward 7 +up 4 +up 5 +down 5 +forward 9 +down 1 +forward 2 +down 6 +forward 9 +down 4 +down 2 +forward 2 +up 7 +forward 7 +forward 8 +up 9 +forward 3 +up 1 +down 5 +forward 5 +down 1 +up 5 +forward 4 +forward 5 +up 3 +down 4 +up 6 +up 1 +down 2 +forward 6 +down 8 +up 9 +down 7 +forward 9 +down 8 +forward 3 +forward 8 +down 1 +down 7 +forward 6 +up 6 +down 1 +down 5 +forward 6 +down 7 +down 2 +forward 6 +forward 2 +forward 8 +forward 7 +forward 2 +down 7 +up 2 +down 7 +forward 8 +forward 8 +forward 2 +forward 4 +down 1 +down 6 +down 1 +down 4 +down 4 +down 2 +down 7 +up 5 +up 5 +down 1 +forward 3 +up 1 +down 3 +forward 9 +forward 4 +forward 7 +down 4 +down 4 +down 2 +forward 2 +forward 1 +forward 9 +down 1 +down 4 +down 1 +forward 4 +up 8 +forward 3 +down 6 +forward 5 +forward 9 +forward 1 +up 8 +down 7 +down 8 +forward 4 +down 4 +up 5 +down 3 +forward 3 +down 6 +down 1 +down 9 +forward 8 +up 5 +down 7 +up 7 +forward 3 +up 5 +up 7 +down 4 +up 2 +down 2 +down 8 +up 6 +down 4 +up 1 +down 8 +down 4 +forward 7 +down 4 +up 3 +down 9 +forward 3 +up 4 +up 1 +up 5 +down 4 +forward 4 +forward 4 +down 2 +down 3 +down 4 +forward 2 +down 9 +down 9 +down 6 +forward 5 +forward 7 +down 3 +forward 2 +up 8 +down 6 +down 8 +down 2 +up 9 +down 1 +forward 8 +forward 1 +forward 8 +up 4 +up 1 +down 8 +up 2 +forward 5 +down 3 +forward 5 +forward 4 +forward 1 +down 9 +forward 2 +forward 5 +forward 4 +forward 3 +down 7 +up 9 +forward 7 +up 8 +forward 3 +forward 3 +down 5 +forward 7 +forward 5 +down 4 +forward 6 +down 6 +up 3 +down 3 +forward 7 +forward 8 +up 3 +up 8 +forward 8 +up 4 +forward 5 +up 4 +down 7 +forward 4 +down 8 +down 6 +forward 7 +down 4 +up 7 +down 6 +up 5 +down 2 +forward 7 +down 7 +up 3 +up 3 +down 3 +down 5 +forward 3 +forward 5 +forward 8 +down 3 +down 8 +forward 3 +down 1 +forward 4 +up 5 +forward 8 +up 1 +up 4 +down 4 +forward 1 +forward 6 +up 7 +up 1 +up 7 +down 5 +forward 8 +down 1 +forward 1 +forward 6 +up 9 +up 6 +down 4 +forward 5 +down 1 +forward 7 +down 8 +up 3 +down 9 +down 1 +up 7 +up 6 +forward 8 +down 9 +down 4 +forward 4 +up 7 +down 3 +forward 5 +forward 8 +up 5 +down 7 +up 2 +forward 3 +forward 3 +forward 4 +down 1 +forward 5 +forward 7 +up 7 +forward 7 +forward 1 +forward 3 +forward 9 +down 3 +forward 5 +down 9 +down 7 +down 4 +down 8 +up 3 +down 1 +up 5 +down 5 +forward 2 +down 6 +down 5 +forward 2 +forward 6 +down 6 +up 6 +down 8 +up 1 +forward 4 +forward 2 +forward 1 +up 1 +forward 5 +forward 3 +forward 7 +down 9 +forward 3 +down 9 +up 5 +down 7 +down 2 +down 3 +up 5 +up 3 +down 2 +forward 4 +forward 1 +down 3 +up 4 +down 8 +down 1 +forward 6 +down 3 +forward 9 +down 7 +down 3 +down 4 +down 5 +up 1 +forward 8 +forward 2 +up 3 +up 7 +up 1 +forward 3 +forward 9 +up 5 +forward 6 +down 8 +down 9 +down 5 +forward 6 +forward 3 +forward 8 +forward 7 +forward 9 +forward 2 +up 9 +forward 8 +down 2 +down 6 +down 9 +down 5 +forward 1 +down 7 +forward 2 +down 4 +down 1 +up 1 +down 2 +forward 5 +forward 8 +down 9 +up 6 +forward 8 +forward 3 +up 6 +up 2 +forward 8 +down 8 +up 1 +down 6 +down 2 +down 6 +forward 5 +forward 6 +down 4 +forward 1 +down 4 +up 7 +forward 4 +up 1 +forward 9 +forward 7 +up 3 +down 7 +down 4 +forward 3 +forward 8 +forward 6 +forward 6 +up 1 +up 2 +up 8 +down 7 +forward 8 +down 5 +forward 6 +down 1 +down 9 +down 2 +forward 6 +up 3 +down 5 +down 6 +forward 1 +forward 2 +down 3 +forward 8 +forward 1 +up 5 +down 8 +down 4 +up 9 +up 2 +forward 7 +forward 9 +up 8 +up 6 +forward 1 +down 7 +up 1 +down 3 +forward 2 +forward 3 +down 3 +down 2 +forward 3 +down 7 +forward 3 +forward 7 +forward 7 +down 8 +down 4 +forward 3 +forward 4 +down 7 +down 9 +down 4 +down 2 +forward 7 +up 8 +down 4 +down 3 +forward 9 +down 5 +up 6 +up 2 +down 5 +down 6 +forward 2 +forward 8 +down 1 +forward 6 +up 7 +down 6 +forward 4 +down 2 +down 5 +down 9 +forward 7 +up 4 +forward 9 +up 7 +down 4 +down 6 +up 9 +forward 1 +up 7 +down 5 +forward 3 +forward 3 +down 7 +down 1 +down 7 +down 7 +down 1 +forward 8 +forward 9 +forward 8 +down 9 +down 8 +down 5 +down 3 +forward 4 +forward 1 +down 1 +forward 1 +down 7 +forward 7 +forward 3 +down 8 +forward 3 +forward 9 +forward 8 +down 7 +forward 8 +down 2 +up 5 +forward 7 +forward 4 +down 2 +up 6 +up 8 +forward 7 +down 9 +up 3 +forward 4 +up 9 +up 5 +up 5 +up 6 +down 4 +down 5 +up 5 +forward 7 +forward 6 +down 4 +forward 5 +forward 4 +up 7 +forward 8 +down 2 +forward 1 +down 9 +down 8 +forward 7 +down 7 +down 1 +forward 9 +down 7 +forward 6 +down 2 +up 9 +forward 1 +up 9 +down 3 +up 9 +down 1 +forward 1 +down 1 +up 6 +down 8 +up 2 +down 3 +forward 1 +down 4 +up 5 +down 5 +down 4 +forward 5 +forward 4 +down 9 +up 7 +down 7 +forward 7 +forward 6 +forward 8 +down 8 +forward 8 +down 1 +down 1 +down 8 +down 2 +up 2 +up 1 +forward 5 +down 1 +up 5 +up 2 +down 6 +up 8 +forward 5 +down 8 +down 1 +up 5 +down 1 +forward 4 +down 6 +down 4 +forward 2 +forward 2 +down 1 +up 4 +up 8 +down 6 +down 2 +forward 5 +forward 8 +forward 7 +down 5 +down 7 +down 3 +forward 6 +down 3 +down 3 +forward 6 +forward 6 +forward 6 +up 7 +forward 1 +down 5 +down 2 +up 8 +forward 6 +down 7 +down 6 +forward 1 +up 5 +down 4 +up 9 +forward 3 +up 3 +forward 9 +forward 9 +forward 7 +forward 5 +down 9 +forward 1 +forward 6 +up 8 +down 7 +forward 9 +forward 5 +up 4 +down 8 +forward 8 +forward 4 +down 9 +up 2 +forward 5 +forward 8 +down 8 +down 9 +down 9 +forward 4 +forward 8 +down 5 +down 5 +forward 5 +forward 5 +up 9 +up 7 +forward 3 +up 4 +down 8 +up 6 +up 6 +down 4 +down 3 +forward 2 +forward 9 +down 4 +down 2 +forward 4 +up 9 +forward 1 +down 8 +down 9 +down 9 +down 3 +forward 1 +down 5 +up 9 +forward 6 +up 4 +forward 2 +forward 2 +forward 4 +down 9 +up 5 +up 1 +down 6 +forward 7 +down 8 +forward 4 +forward 9 +up 9 +up 4 +down 5 +down 3 +forward 2 +down 8 +down 6 +forward 3 +down 2 +forward 6 +up 2 +forward 6 +down 7 +up 4 +forward 1 +forward 4 +up 4 +forward 6 +forward 8 +down 7 +down 6 +up 7 +down 2 +down 4 +down 5 +forward 1 +up 4 +forward 8 +forward 6 +down 8 +up 5 +up 2 +up 9 +up 5 +forward 6 +down 4 +up 3 +down 8 +down 6 +down 2 +up 3 +up 5 +down 1 +forward 9 +up 8 +up 2 +down 3 +forward 6 +down 1 +forward 5 +down 3 +up 1 +up 2 +down 5 +down 7 +forward 8 +down 8 +up 9 +forward 3 +down 8 +down 8 +forward 1 +down 4 +down 4 +forward 3 +up 6 +down 3 +down 7 +down 7 +up 1 +forward 3 +forward 2 @@ -0,0 +1,28 @@ +Command = tuple[str, int] + +def part1(commands: list[Command]) -> int: + pos: int = 0 + depth: int = 0 + for command in commands: + match command: + case ('up', X): depth -= X + case ('down', X): depth += X + case ('forward', X): pos += X + return pos * depth + +def part2(commands: list[Command]) -> int: + pos: int = 0 + aim: int = 0 + depth: int = 0 + for command in commands: + match command: + case ('up', X): aim -= X + case ('down', X): aim += X + case ('forward', X): + pos += X + depth += aim * X + return pos * depth + +commands: list[Command] = [(c, int(q)) for c, q in (l.split() for l in open('2.in'))] +print(part1(commands)) +print(part2(commands)) |