Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 92e121f

Browse files
committedOct 10, 2024·
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 63e4798 commit 92e121f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎dynamic_programming/travelling_salesman_problem.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ def visit(city: int, mask: int) -> int:
4646
if mask == VISITED_ALL:
4747
return distances[city][0] # Return to the starting city
4848

49-
min_cost = float('inf')
49+
min_cost = float("inf")
5050
for next_city in range(n):
5151
if not mask & (1 << next_city): # If the next_city is not visited
52-
new_cost = distances[city][next_city] + visit(next_city, mask | (1 << next_city))
52+
new_cost = distances[city][next_city] + visit(
53+
next_city, mask | (1 << next_city)
54+
)
5355
min_cost = min(min_cost, new_cost)
5456
return min_cost
5557

@@ -60,5 +62,9 @@ def visit(city: int, mask: int) -> int:
6062
import doctest
6163

6264
doctest.testmod()
63-
print(f"{tsp([[0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0]]) = }")
64-
print(f"{tsp([[0, 29, 20, 21], [29, 0, 15, 17], [20, 15, 0, 28], [21, 17, 28, 0]]) = }")
65+
print(
66+
f"{tsp([[0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0]]) = }"
67+
)
68+
print(
69+
f"{tsp([[0, 29, 20, 21], [29, 0, 15, 17], [20, 15, 0, 28], [21, 17, 28, 0]]) = }"
70+
)

0 commit comments

Comments
 (0)
Please sign in to comment.