Skip to content

Commit

Permalink
day17: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ong committed Dec 27, 2023
1 parent 80a0810 commit 80432cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions day17/lib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ def __init__(self, num_rows: int, num_cols: int, cache_min: int, cache_max: int)
]

def add_solution(self, step: Step) -> bool:
"""adds solution to cache"""
"""adds solution to cache returns whether an improvement was made"""
tile_cache = self.cache[step.row][step.col]
existing_item = tile_cache[step.direction, step.consecutive_steps]
if existing_item is None:
tile_cache[step.direction, step.consecutive_steps] = step
return True

# due to the way that we run in BFS, we shouldn't be getting
# into this branch
if step.total_cost < existing_item.total_cost:
tile_cache[step.direction, step.consecutive_steps] = step
return True
raise AssertionError("this shouldn't be possible")
# tile_cache[step.direction, step.consecutive_steps] = step
# return True
return False


Expand Down Expand Up @@ -114,7 +117,7 @@ def solve(self) -> Step:
if (new_step := self.create_step(step, direction)) is not None:
steps_to_explore.put(new_step)

raise ValueError("No solution found!")
raise AssertionError("No solution found!")

def is_oob(self, row: int, col: int) -> bool:
"""true if laser is out of bounds"""
Expand Down Expand Up @@ -169,4 +172,4 @@ def solve(self) -> Step:
for direction in ALL_DIRECTIONS:
if (new_step := self.create_step(step, direction)) is not None:
steps_to_explore.put(new_step)
raise ValueError("No solution found!")
raise AssertionError("No solution found!")
6 changes: 3 additions & 3 deletions day17/lib/direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __str__(self) -> str:
return "v"
elif self == Direction.WEST:
return "<"
raise ValueError("invalid value")
raise AssertionError("invalid value")

def opposite(self) -> "Direction":
int_value = int(self)
Expand All @@ -36,7 +36,7 @@ def offset(self, row: int, col: int) -> tuple[int, int]:
return (row + 1, col)
if self == Direction.WEST:
return (row, col - 1)
raise ValueError("direction not suppported", self)
raise AssertionError("direction not suppported", self)

def offset_list(self, row: int, col: int, size: int = 4) -> list[tuple[int, int]]:
offsets = range(1, size + 1)
Expand All @@ -48,7 +48,7 @@ def offset_list(self, row: int, col: int, size: int = 4) -> list[tuple[int, int]
return [(row + i, col) for i in offsets]
if self == Direction.WEST:
return [(row, col - i) for i in offsets]
raise ValueError("direction not suppported", self)
raise AssertionError("direction not suppported", self)


ALL_DIRECTIONS = list(Direction)

0 comments on commit 80432cc

Please sign in to comment.