• API
• FAQ
• Tools
• Archive
SHARE
TWEET

ciclo

Daboposki May 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def ciclo(lista, aux):
2.     recorrido = [aux]
3.     return cicloInm(recorrido, lista)
4. def cicloInm(recorrido, lista):
5.     if recorrido[0]==recorrido[-1] and len(recorrido)>1:
6.         return lista, recorrido
7.     else:
8.         i = 0
9.         while i<len(lista):
10.             if(recorrido[-1]==lista[i][0] or recorrido[-1]==lista[i][1]):
11.                 aux = lista[i]
12.                 if(aux[0]==recorrido[-1]):
13.                     lista.remove(aux)
14.                     recorrido.append(aux[1])
15.                     return cicloInm(recorrido,lista)
16.                     recorrido.remove(recorrido[-1])
17.                     lista.insert(i,aux)
18.                 elif (aux[1]==recorrido[-1]):
19.                     lista.remove(aux)
20.                     recorrido.append(aux[0])
21.                     return cicloInm(recorrido,lista)
22.                     recorrido.remove(recorrido[-1])
23.                     lista.insert(i,aux)
24.             i = i + 1
25.
26. ciclo([(1,2),(1,3),(2,3),(2,4),(3,4),(3,5),(5,6),(5,7),(5,8),(6,7),(6,8),(7,8),(7,9),(8,9)],1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top