Skip to content

Commit acf647e

Browse files
authored
Update travelling_salesman_problem.py
1 parent 612b116 commit acf647e

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

dynamic_programming/travelling_salesman_problem.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def visit(city: int, mask: int) -> int:
3737
"""Recursively calculates the minimum cost to visit all cities."""
3838
if mask == visited_all:
3939
return distances[city][0] # Return to the starting city
40-
4140
if memo[city][mask] != -1: # Return cached result if exists
4241
return memo[city][mask]
4342
min_cost = float("inf") # Use infinity for initial comparison
@@ -49,14 +48,8 @@ def visit(city: int, mask: int) -> int:
4948
min_cost = min(min_cost, new_cost)
5049
memo[city][mask] = int(min_cost) # Store result as an integer
5150
return memo[city][mask] # Return the cached result
52-
5351
return visit(0, 1) # Start from city 0 with city 0 visited
5452

55-
5653
if __name__ == "__main__":
5754
import doctest
58-
59-
try:
60-
doctest.testmod()
61-
except Exception as e:
62-
print(f"An error occurred during doctest: {e}")
55+
doctest.testmod()

0 commit comments

Comments
 (0)