|
1234567891011121314151617181920212223242526272829 |
- def main():
- """
- horizontal position, vertical position, and aim both start at 0
- forward X increases forward (horizontal) position by X units
- AND changes depth by (X * aim) units
- down X increases aim (vertical angle) by X units
- up X decreases aim (vertical angle) by X units
- After following all instructions multiply final h_pos by final v_pos
- """
- h_pos, v_pos, aim = 0, 0, 0
- instructions = []
- with open("aoc2-1.txt", "r") as file:
- instructions = file.readlines()
- for inst in instructions:
- dir, amt = inst.strip().split(" ")
- amt = int(amt)
- if dir == "forward":
- h_pos += amt
- v_pos += (amt * aim)
- elif dir == "down":
- aim += amt
- elif dir == "up":
- aim -= amt
- else:
- raise ValueError(f"Unrecognized direction: {h_pos}")
- return (h_pos * v_pos)
-
- if __name__ == "__main__":
- print(main())
|