Skip to content

Instantly share code, notes, and snippets.

@narenpertuz
Created May 27, 2021 18:20
Show Gist options
  • Save narenpertuz/815a2380704c47850c9641603b7f3865 to your computer and use it in GitHub Desktop.
Save narenpertuz/815a2380704c47850c9641603b7f3865 to your computer and use it in GitHub Desktop.
Segunda prueba tecnica de Naren Pertuz Vides
M,P
P,A
A,C
P,T
T,C
#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;
}
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