diff options
Diffstat (limited to '2021/02.py')
-rw-r--r-- | 2021/02.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/2021/02.py b/2021/02.py new file mode 100644 index 0000000..2489b90 --- /dev/null +++ b/2021/02.py @@ -0,0 +1,30 @@ +# Day Two: Dive! + +file = open("input/02.txt").readlines() + +hori = 0 +depth = 0 + +for line in file: + com = line.split() + if com[0] == "forward": + hori += int(com[1]) + if com[0] == "up": + depth -= int(com[1]) + if com[0] == "down": + depth += int(com[1]) +print(hori * depth) + +hori = 0 +depth = 0 +aim = 0 +for line in file: + com = line.split() + if com[0] == "forward": + hori += int(com[1]) + depth += aim * int(com[1]) + if com[0] == "up": + aim -= int(com[1]) + if com[0] == "down": + aim += int(com[1]) +print(hori * depth) |