Skip to content

Commit a1bd736

Browse files
authored
Update travelling_salesman_problem.py
1 parent 20c297f commit a1bd736

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

dynamic_programming/travelling_salesman_problem.py

-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def tsp(distances: list[list[int]]) -> int:
3232
# Memoization table
3333
memo = [[-1] * (1 << n) for _ in range(n)]
3434
visited_all = (1 << n) - 1 # All cities visited mask
35-
3635
def visit(city: int, mask: int) -> int:
3736
"""Recursively calculates the minimum cost to visit all cities."""
3837
if mask == visited_all:
@@ -48,10 +47,7 @@ def visit(city: int, mask: int) -> int:
4847
min_cost = min(min_cost, new_cost)
4948
memo[city][mask] = int(min_cost) # Store result as an integer
5049
return memo[city][mask] # Return the cached result
51-
5250
return visit(0, 1) # Start from city 0 with city 0 visited
53-
54-
5551
if __name__ == "__main__":
5652
import doctest
5753

0 commit comments

Comments
 (0)