diff options
author | j-james | 2021-12-02 05:06:58 +0000 |
---|---|---|
committer | j-james | 2021-12-02 08:58:29 +0000 |
commit | 4998c58a68c71101e63133bb5501b28be72093c7 (patch) | |
tree | ac82ad15558312b322bd332605454abf315a22c0 /2021/02.py | |
parent | d325ab6752b37294ce62918c797ff30084bcf0b4 (diff) |
Day Two
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) |