Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import math
  2. n = 8
  3.  
  4. ans = []
  5. myset = set()
  6.  
  7. for i in range(1, n + 1):
  8. myset.add(i)
  9.  
  10. for i in range(10**(n-1),10**(n)):
  11. temp = set()
  12. count = 0
  13. for j in str(i):
  14. if int(j) not in myset:
  15. break
  16. if int(j) not in temp:
  17. count += 1
  18. temp.add(int(j))
  19. if count == n:
  20. ans.append(str(i))
  21.  
  22. for j in ans:
  23. temp = []
  24. cycles= []
  25. while len(temp) != n:
  26. cycle = []
  27. for i in j:
  28. if int(i) not in temp:
  29. ind = int(i)
  30. break
  31. while True:
  32. ind = int(j[int(ind) - 1])
  33. if ind in cycle:
  34. break
  35. cycle.append(ind)
  36. temp.append(ind)
  37. cycles.append("("+",".join([str(e) for e in cycle])+")")
  38. print ("".join(cycles))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement