2020: d02: ex1: add solution

This commit is contained in:
Bruno BELANYI 2021-12-02 10:10:29 +01:00
parent 9d9dec0715
commit 4195a9e321

32
2021/d02/ex1/ex1.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import itertools
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()