def part1(self): grid = InfiniteGrid[bool]() santa = Coordinate(0, 0) grid[santa] = True for character in self.path: santa = santa.move(character) grid[santa] = True result = len(grid.find(True)) print("Part 1:", result)
def _get_keycode(self, keypad: Grid[str]): coordinate = Coordinate(1, 1, system=CoordinateSystem.X_RIGHT_Y_DOWN) result = "" for line in self.lines: for character in line: new_coordinate = coordinate.move(character) if keypad[new_coordinate] is not None: coordinate = new_coordinate result += keypad[coordinate] return result
def part2(self): grid = InfiniteGrid[bool]() santa = Coordinate(0, 0) robot_santa = santa grid[santa] = True for index, character in enumerate(self.path): if index % 2 == 0: santa = santa.move(character) grid[santa] = True else: robot_santa = robot_santa.move(character) grid[robot_santa] = True result = len(grid.find(True)) print("Part 2:", result)