Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
recursion solution in Clear category for All Roads Lead to Rome! by kdim
def lattice_paths(position: tuple[int, int], tabu: list[tuple[int, int]]) -> int:
x, y = position
if x == y == 0:
return 1
if position in tabu:
return 0
if (0, 1) in tabu and (1, 0) in tabu:
return 0
return sum(lattice_paths((x + dx, y + dy), tabu) for dx, dy in ((-1, 0), (0, -1)) if x + dx >= 0 <= y + dy)
Nov. 24, 2024
Comments: