Skip to content

Commit a0acf30

Browse files
committed
Day 24: attempt to fix the dfs but fail
1 parent 2032997 commit a0acf30

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

day24/stringsRearrangementBacktracking.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,25 @@ def createGraph(inputTuples):
3232
def derp(graph, startTuple, visited=set()):
3333
# do dfs
3434
for vertexTuple in graph[startTuple]:
35+
print vertexTuple
3536
if vertexTuple not in visited:
3637
visited.add(vertexTuple)
3738
if derp(graph, vertexTuple, visited):
3839
return True
39-
40+
print visited
41+
42+
if len(visited) == len(graph):
43+
return True
4044
return False
4145

4246
def hamiltonianPath(graph):
4347
if len(graph) == 0:
4448
return True
4549

46-
visited = set()
50+
print graph
4751
for node in graph:
48-
if node not in visited and derp(graph, node, visited):
52+
if derp(graph, node):
4953
return True
50-
visited.add(node)
5154

5255
return False
5356

0 commit comments

Comments
 (0)