35 lines
627 B
Python
35 lines
627 B
Python
with open("2.txt") as f:
|
|
data = f.read()
|
|
with open("2.txt") as f:
|
|
lines = list(map(lambda s: s.rstrip(), f.readlines()))
|
|
|
|
x = 0
|
|
y = 0
|
|
for line in lines:
|
|
if not line: continue
|
|
p = line.split(" ")
|
|
n = int(p[1])
|
|
if p[0] == "forward":
|
|
x += n
|
|
elif p[0] == "down":
|
|
y += n
|
|
elif p[0] == "up":
|
|
y -= n
|
|
|
|
print(x * y)
|
|
|
|
x = 0
|
|
y = 0
|
|
aim = 0
|
|
for line in lines:
|
|
if not line: continue
|
|
p = line.split(" ")
|
|
n = int(p[1])
|
|
if p[0] == "forward":
|
|
x += n
|
|
y += aim * n
|
|
elif p[0] == "down":
|
|
aim += n
|
|
elif p[0] == "up":
|
|
aim -= n
|
|
print(x * y)
|