aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

b.py (367B) [raw]


      1 #!/usr/bin/env python3
      2 import sys
      3 
      4 depth = 0
      5 horiz = 0
      6 aim = 0
      7 
      8 for l in sys.stdin:
      9     comm, val = l.split()
     10     if comm == "down":
     11         aim += int(val)
     12     elif comm == "up":
     13         aim -= int(val)
     14     elif comm == "forward":
     15         horiz += int(val)
     16         depth += aim * int(val)
     17     else:
     18         raise Exception(f"bad comm: {comm}")
     19 
     20 print(horiz * depth)