Advertisement
manianis

Permutation de chiffres 1..n

Mar 26th, 2023
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | Source Code | 0 0
  1. from numpy import array
  2.  
  3. def fact(n):
  4.     f = 1
  5.     for i in range(2, n+1):
  6.         f = f * i
  7.     return f
  8.  
  9. n = 5
  10. m = array([array([int()]*fact(n))]*n)
  11. m[0, 0] = 1
  12. for i in range(1, n):
  13.     ne = fact(i)
  14.     cnt = 0
  15.     for j in range(ne):
  16.         ch = str(m[i-1, j])
  17.         for k in range(len(ch)+1):
  18.             ch1 = ch[:k] + str(i+1) + ch[k:]
  19.             m[i, cnt] = int(ch1)
  20.             cnt += 1
  21.  
  22. for i in range(n):
  23.     ne = fact(i + 1)
  24.     print(m[i, :ne])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement