day 2
This commit is contained in:
parent
02c8ed3933
commit
c898811c9f
19
2/a.py
Normal file
19
2/a.py
Normal file
@ -0,0 +1,19 @@
|
||||
with open("input.txt") as f:
|
||||
lines = [i for i in f.readlines()]
|
||||
|
||||
|
||||
depth = 0
|
||||
hpos = 0
|
||||
|
||||
for line in lines:
|
||||
verb, val = line.strip().split()
|
||||
val = int(val)
|
||||
|
||||
if verb == "forward":
|
||||
hpos += val
|
||||
elif verb == "down":
|
||||
depth += val
|
||||
elif verb == "up":
|
||||
depth -= val
|
||||
|
||||
print(depth * hpos)
|
24
2/b.py
Normal file
24
2/b.py
Normal file
@ -0,0 +1,24 @@
|
||||
with open("input.txt") as f:
|
||||
lines = [i for i in f.readlines()]
|
||||
|
||||
|
||||
depth = 0
|
||||
hpos = 0
|
||||
aim = 0
|
||||
|
||||
|
||||
for line in lines:
|
||||
verb, val = line.strip().split()
|
||||
val = int(val)
|
||||
|
||||
if verb == "forward":
|
||||
hpos += val
|
||||
depth += (aim * val)
|
||||
elif verb == "down":
|
||||
aim += val
|
||||
elif verb == "up":
|
||||
aim -= val
|
||||
|
||||
print(depth * hpos)
|
||||
|
||||
# 5m16s
|
1000
2/input.txt
Normal file
1000
2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user