Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Permutations/Python/permutations-2.py
Normal file
26
Task/Permutations/Python/permutations-2.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
def perm1(n):
|
||||
a = list(range(n))
|
||||
def sub(i):
|
||||
if i == n - 1:
|
||||
yield tuple(a)
|
||||
else:
|
||||
for k in range(i, n):
|
||||
a[i], a[k] = a[k], a[i]
|
||||
yield from sub(i + 1)
|
||||
a[i], a[k] = a[k], a[i]
|
||||
yield from sub(0)
|
||||
|
||||
def perm2(n):
|
||||
a = list(range(n))
|
||||
def sub(i):
|
||||
if i == n - 1:
|
||||
yield tuple(a)
|
||||
else:
|
||||
for k in range(i, n):
|
||||
a[i], a[k] = a[k], a[i]
|
||||
yield from sub(i + 1)
|
||||
x = a[i]
|
||||
for k in range(i + 1, n):
|
||||
a[k - 1] = a[k]
|
||||
a[n - 1] = x
|
||||
yield from sub(0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue