|
123456789101112131415161718192021222324252627 |
- def main():
- """
- horizontal position and vertical position both start at 0
- forward X increases forward (horizontal) position by X units
- down X increases depth (vertical position) by X units
- up X decreases depth (vertical position) by X units
- After following all instructions multiply final h_pos by final v_pos
- """
- h_pos, v_pos = 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
- elif dir == "down":
- v_pos += amt
- elif dir == "up":
- v_pos -= amt
- else:
- raise ValueError(f"Unrecognized direction: {h_pos}")
- return (h_pos * v_pos)
-
- if __name__ == "__main__":
- print(main())
|