day 2
This commit is contained in:
parent
02c8ed3933
commit
c898811c9f
|
@ -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)
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue