Skip to content

Commit

Permalink
day21: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ong committed Dec 28, 2023
1 parent 6761b8d commit 8598437
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 11 additions & 7 deletions day21/day21.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ def mini_solve(
# This means we need 130 steps(?) to hit the corners,
# and 131 to get to next centre
def solve(
start_pos: Position, maze: Maze, steps: int, unlimited_map: bool = False
start_pos: Position,
maze: Maze,
steps: int,
unlimited_map: bool = False,
smart_unlimited: bool = True, # for > 3 boards wide, use smart algo
) -> int:
distances: BaseDistanceMaze
if unlimited_map:
distances = DistanceMazes(maze.num_rows, maze.num_cols)
else: # small
distances = DistanceMaze(maze.num_rows, maze.num_cols)

if smart_unlimited and unlimited_map:
board_size = maze.num_rows

steps_remaining = steps % board_size
Expand All @@ -89,14 +96,11 @@ def solve(
sim_steps = board_size * 2 + steps_remaining
else:
sim_steps = board_size * 3 + steps_remaining
# sim_steps = steps #uncomment to brute force
else: # small
distances = DistanceMaze(maze.num_rows, maze.num_cols)
else:
sim_steps = steps

distances = mini_solve(start_pos, maze, sim_steps, distances)

if not unlimited_map:
if not unlimited_map or (unlimited_map and not smart_unlimited):
print(distances.overlay(maze))
return distances.calc_steps(sim_steps % 2)

Expand Down Expand Up @@ -127,7 +131,7 @@ def main() -> None:
print(solve(start_pos, maze, 64))

# part2
print(solve(start_pos, maze, GIGA_TARGET, True))
print(solve(start_pos, maze, GIGA_TARGET, True, True))


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions day21/tests/test_day21.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ def test_day21() -> None:

assert solve(start_pos, maze, int(maze.num_rows * 3.5), True) == 1521
assert solve(start_pos, maze, int(maze.num_rows * 4.5), True) == 2500

assert solve(start_pos, maze, int(maze.num_rows * 3.5), True, False) == 1521

0 comments on commit 8598437

Please sign in to comment.