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 /2.py | |
parent | 1f88313cc4ff52f06b5c99ff2364910d8bc10e1d (diff) | |
download | aoc2021-72724bb3a507465b8f1df65eeb6a3bee62549705.tar.gz aoc2021-72724bb3a507465b8f1df65eeb6a3bee62549705.tar.xz aoc2021-72724bb3a507465b8f1df65eeb6a3bee62549705.zip |
day 2
Diffstat (limited to '2.py')
-rw-r--r-- | 2.py | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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)) |