2
1
Fork 0

Day 2: Add Python solution

This commit is contained in:
Mia Herkt 2021-12-02 10:49:11 +01:00
parent 473bc79995
commit d57d26d9e1
Signed by: mia
GPG key ID: 72E154B8622EC191
3 changed files with 1023 additions and 0 deletions

1000
02/input.txt Normal file

File diff suppressed because it is too large Load diff

9
02/solution_1.py Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env python3
from collections import defaultdict
d = defaultdict(int)
with open("input.txt", "r") as _input:
for i, n in [x.split(' ') for x in _input.readlines()]:
d[i] += int(n)
print("Answer:", (d["down"] - d["up"]) * d["forward"])

14
02/solution_2.py Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env python3
aim = 0
h = 0
v = 0
with open("input.txt", "r") as _input:
for i, n in [x.split(' ') for x in _input.readlines()]:
n = int(n)
if i == "down": aim += n
elif i == "up": aim -= n
elif i == "forward": h += n; v += aim * n
print("Answer:", h * v)