Select Git revision
graph-check-color.py
Forked from
Vuillemot Romain / INF-TC1
Source project has a limited visibility.
-
Romain Vuillemot authoredRomain Vuillemot authored
graph-similarite.py 834 B
# Par exemple pour Fool et Sage vous devez renvoyez le résultat suivant :
#
# FOOL
# POOL
# POLL
# POLE
# PALE
# SALE
# SAGE
#
# SOLUTION:
graph = {'A': ['B', 'C'],
'B': ['C', 'D'],
'C': ['D'],
'D': ['C'],
'E': ['F'],
'F': ['C']
}
def chemin(graphe, source, destination, visite=None):
if source == destination:
return [destination]
else:
visite = visite or set()
for s in graphe[source]:
if s not in visite:
visite.add(s)
print("trace:", source + " > " + s)
sous_chemin = chemin(graphe, s, destination, visite)
if sous_chemin is not None:
return [source] + sous_chemin
print(chemin(simGraphe(["AA", "AB", "BC", "AC", "DD"]), "AA", "BC"))
# ['AA', 'AB', 'AC', 'BC']