123456789101112131415161718192021222324 |
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument("ifile", type=argparse.FileType('r'))
- args = parser.parse_args()
- lines = [line.strip() for line in args.ifile.readlines()]
- hpos = 0
- depth = 0
- for line in lines:
- stuff = line.split(' ')
- command = stuff[0]
- parameter = int(stuff[1])
- if command == "forward":
- hpos += parameter
- elif command == "down":
- depth += parameter
- elif command == "up":
- depth -= parameter
- print(hpos * depth)
|