Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from aoc.intcomp import IntComp
- computer = IntComp("day15.txt")
- command = 1
- x, y = (0, 0)
- valid_squares = []
- def try_squares():
- for i in range(1, 5):
- computer.run_program(i)
- status = computer.get_output()[0]
- computer.clear_output()
- if status == 0:
- # Blocked
- pass
- elif status == 1:
- # Move successful
- update_coords(i)
- valid_squares.append((x, y))
- return_to_last(i)
- elif status == 2:
- # Goal found
- print('Found the goal')
- break
- def update_coords(direction):
- global x, y
- if direction == 1:
- y += 1 # North
- elif direction == 2:
- y -= 1 # South
- elif direction == 3:
- x -= 1 # West
- elif direction == 4:
- x += 1 # East
- def return_to_last(direction_moved):
- opposite = {1: 2, 2: 1, 3: 4, 4: 3}
- computer.run_program(opposite[direction_moved])
- update_coords(opposite[direction_moved])
- try_squares()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement