Bruno BELANYI
f9fc9fbd6b
This is mostly about unused imports. A couple errors remain, but are fine in my book (using `l` as a variable name, assigning a lambda to a variable).
32 lines
578 B
Python
Executable file
32 lines
578 B
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import sys
|
|
from typing import List
|
|
|
|
|
|
def solve(input: List[str]) -> int:
|
|
x, y = 0, 0
|
|
|
|
for instruction in input:
|
|
dir, length_ = instruction.split(" ")
|
|
length = int(length_)
|
|
if dir == "forward":
|
|
x += length
|
|
elif dir == "down":
|
|
y += length
|
|
elif dir == "up":
|
|
y -= length
|
|
else:
|
|
assert False
|
|
|
|
return x * y
|
|
|
|
|
|
def main() -> None:
|
|
input = [line.strip() for line in sys.stdin.readlines()]
|
|
print(solve(input))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|