with open("input") as f: puzzle_input = f.read() # puzzle_input = "^v^v^v^v^v" coords = (0, 0) delivered_houses = set() delivered_houses.add(coords) MOVEMENTS = {">": (1, 0), "^": (0, 1), "<": (-1, 0), "v": (0, -1)} SANTA_MOVES = puzzle_input[::2] ROBO_MOVES = puzzle_input[1::2] for char in SANTA_MOVES: [d_x, d_y] = MOVEMENTS[char] coords = (coords[0] + d_x, coords[1] + d_y) delivered_houses.add(coords) coords = (0, 0) for char in ROBO_MOVES: [d_x, d_y] = MOVEMENTS[char] coords = (coords[0] + d_x, coords[1] + d_y) delivered_houses.add(coords) print(len(delivered_houses))