Skip to content

Commit aaef0d6

Browse files
author
khanhkhanhlele
committed
backtracking/hamiltonian_cycle.py create main function
1 parent e2a78d4 commit aaef0d6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

backtracking/hamiltonian_cycle.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,16 @@ def hamilton_cycle(graph: list[list[int]], start_index: int = 0) -> list[int]:
174174
path[0] = path[-1] = start_index
175175
# evaluate and if we find answer return path either return empty array
176176
return path if util_hamilton_cycle(graph, path, 1) else []
177+
178+
if __name__ == "__main__":
179+
import doctest
180+
181+
doctest.testmod()
182+
graph = [
183+
[0, 1, 0, 1, 0],
184+
[1, 0, 1, 1, 1],
185+
[0, 1, 0, 0, 1],
186+
[1, 1, 0, 0, 1],
187+
[0, 1, 1, 1, 0],
188+
]
189+
print(hamilton_cycle(graph))

0 commit comments

Comments
 (0)