diff options
author | Brian Chu <brianmchu42@gmail.com> | 2021-12-04 12:49:24 -0800 |
---|---|---|
committer | Brian Chu <brianmchu42@gmail.com> | 2021-12-04 12:49:24 -0800 |
commit | f248d715d4a3c19f84475fcb6d076a6874fcf7e0 (patch) | |
tree | 6d4c3a75be551e16f41bc7fde6002d6b8e407975 /day2.py | |
download | AdventOfCode2021-f248d715d4a3c19f84475fcb6d076a6874fcf7e0.tar.gz |
commit for days 1 through 4
Diffstat (limited to 'day2.py')
-rw-r--r-- | day2.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/day2.py b/day2.py new file mode 100644 index 0000000..f82eb3a --- /dev/null +++ b/day2.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +depth = 0 +dist = 0 +with open("day2.txt") as data: + for line in data: + match line.split(): + case ["forward", x]: + dist += int(x) + case ["up", x]: + depth -= int(x) + case ["down", x]: + depth += int(x) + print(depth * dist) + +depth = 0 +dist = 0 +aim = 0 +with open("day2.txt") as data: + for line in data: + match line.split(): + case ["forward", x]: + dist += int(x) + depth += aim * int(x) + case ["up", x]: + aim -= int(x) + case ["down", x]: + aim += int(x) + print(depth * dist) |