Created
May 27, 2021 18:20
-
-
Save narenpertuz/815a2380704c47850c9641603b7f3865 to your computer and use it in GitHub Desktop.
Segunda prueba tecnica de Naren Pertuz Vides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
M,P | |
P,A | |
A,C | |
P,T | |
T,C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
FILE *fichero = NULL; | |
char c, aux; | |
fichero = fopen("input.txt", "r"); | |
if(fichero == NULL ) { | |
printf("No fue posible abrir el archivo\n"); | |
return -1; | |
} | |
aux=getc (fichero); | |
while (!feof (fichero)) { | |
c = getc (fichero); | |
if(aux==c){ | |
printf ("\nSi existe un ciclo dentro de la red\n"); | |
fclose(fichero); | |
return 0; | |
} | |
} | |
printf ("\nNo existe un ciclo dentro de la red\n"); | |
fclose(fichero); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
graph = {'M': ['P'], | |
'P': ['A'], | |
'A': ['C'], | |
'P': ['T'], | |
'T': ['C']} | |
def dfs_paths(graph, start, goal): | |
stack = [(start, [start])] | |
while stack: | |
(vertex, path) = stack.pop() | |
print ('path: ' , path) | |
l = list(set(graph[vertex]) - set(path)) | |
for next in sorted(l, reverse=True): | |
if next == goal: | |
yield path + [next] | |
else: | |
stack.append((next, path + [next])) | |
print (next(dfs_paths(graph, 'M', 'T'))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment