-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
35 lines (24 loc) · 698 Bytes
/
run.py
File metadata and controls
35 lines (24 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import sys
from math import *
if len(sys.argv) < 1:
print("too few arguments", file=sys.stderr)
print("usage: {} <input>".format(sys.argv[0]), file=sys.stderr)
exit(1)
inputname = sys.argv[1]
#outputname = sys.argv[2]
horizontal = 0
depth = 0
aim = 0
with open(inputname, "r") as inf:
for line in inf:
instruction = line.split(" ")
amount = int(instruction[1])
if instruction[0] == "forward":
horizontal += amount
depth += aim * amount
elif instruction[0] == "up":
aim -= amount
elif instruction[0] == "down":
aim += amount
print(horizontal*depth)