dieser Code sollte eine Permutation durchführen, das tut er auch.
Aber bei mehrmaligen ausführen werden die aktuellen Ergebnisse immer an die vorherigen Ergebnisse angehängt.
Woran könnte das liegen ?
Code: Alles auswählen
def perm(source, dest=[], done=0, current=[]):
if done == len(source):
if current[0] < current[-1]:
dest.append(current)
else:
for i in source:
if i not in current:
perm(source, dest, done+1, current+[i])
return dest
d=['a','b','c']
perm(d)
[['a', 'b', 'c'], ['a', 'c', 'b'], ['b', 'a', 'c']]
Beim zweiten mal:
perm(d)
[['a', 'b', 'c'], ['a', 'c', 'b'], ['b', 'a', 'c'], ['a', 'b', 'c'], ['a', 'c', 'b'], ['b', 'a', 'c']]
Vielleicht kann mir ja jemand weiter helfen ?
Gruß,
Benni