Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- n = 8
- ans = []
- myset = set()
- for i in range(1, n + 1):
- myset.add(i)
- for i in range(10**(n-1),10**(n)):
- temp = set()
- count = 0
- for j in str(i):
- if int(j) not in myset:
- break
- if int(j) not in temp:
- count += 1
- temp.add(int(j))
- if count == n:
- ans.append(str(i))
- for j in ans:
- temp = []
- cycles= []
- while len(temp) != n:
- cycle = []
- for i in j:
- if int(i) not in temp:
- ind = int(i)
- break
- while True:
- ind = int(j[int(ind) - 1])
- if ind in cycle:
- break
- cycle.append(ind)
- temp.append(ind)
- cycles.append("("+",".join([str(e) for e in cycle])+")")
- print ("".join(cycles))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement