Day 2: Add Python solution
This commit is contained in:
parent
473bc79995
commit
d57d26d9e1
3 changed files with 1023 additions and 0 deletions
1000
02/input.txt
Normal file
1000
02/input.txt
Normal file
File diff suppressed because it is too large
Load diff
9
02/solution_1.py
Executable file
9
02/solution_1.py
Executable 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
14
02/solution_2.py
Executable 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)
|
Loading…
Reference in a new issue