SHARE
TWEET

Untitled

a guest Apr 21st, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n=['1','2','3','4','5','6','7','8']
  2. def obr(m,stroka,k):
  3.     st=stroka
  4.     if st.count(n[0])>=2 and st.count(n[1])>=1 and st.count(n[2])>=1 and st.count(n[3])>=1 and  st.count(n[4])>=1 and st.count(n[5])>=1 and st.count(n[6])>=1 and st.count(n[7])>=1 and st[-1]=='1':
  5.         print (st)
  6.         return st
  7.     for i in range(len(m)):
  8.         if m[i][0]==stroka[-1]:
  9.             k=0
  10.             print(m,stroka,k)
  11.             obr(m[:i]+m[i+1:],stroka+m[i][1], k)
  12.  
  13.         if m[i][1]==stroka[-1]:
  14.             print(m,stroka,k)
  15.             k=0
  16.             obr(m[:i]+m[i+1:],stroka+m[i][0], k)
  17.  
  18.  
  19.  
  20. def nach(teleports_string):
  21.     mas=sorted(teleports_string.split(','))
  22.     k=0
  23.     s=obr(mas,'1',0)
  24.  
  25.     print(s)
  26.  
  27.     #return any route from 1 to 1 over all points
  28.  
  29.     return "123456781"
  30.  
  31.  
  32. nach("12,23,34,45,56,67,78,81") == "123456781"
  33. nach("12,28,87,71,13,14,34,35,45,46,63,65") == "1365417821"
  34. nach("12,15,16,23,24,28,83,85,86,87,71,74,56") == "12382478561"
  35. nach("13,14,23,25,34,35,47,56,58,76,68") == "132586741"
RAW Paste Data
Top