1234567891011121314151617181920212223242526 |
- 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
- aim = 0
- for line in lines:
- stuff = line.split(' ')
- command = stuff[0]
- parameter = int(stuff[1])
- if command == "forward":
- hpos += parameter
- depth += parameter * aim
- elif command == "down":
- aim += parameter
- elif command == "up":
- aim -= parameter
- print(hpos * depth)
|