Permutationen
Verfasst: Dienstag 21. Februar 2023, 15:56
Code: Alles auswählen
def find(v,s,z):
i = len(z)-1
while z[i] < z[v]:
i -= 1
return i
def nextperm(z, n):
s = n
while s > 0 and z[s-1] > z[s]:
s -= 1
v = s-1
i = find(v,s,z)
z[i],z[v] = z[v],z[i]
ende = z[s:]
neu = sorted(ende)
z[s:] = neu
return z[1]==0, z
def zeig(z):
for i in range(1,len(z)):
print(z[i],end = '')
print()
def main(n):
z = []
for i in range(0, n+1):
z.append(i)
b = False
while not b:
zeig(z)
b, z = nextperm(z, n)
main(4)