A permutation on permutations
phil hunt
philh at comuno.freeserve.co.uk
Sun Nov 25 17:37:02 EST 2001
On Sun, 25 Nov 2001 01:18:28 -0500, Arthur Siegel <ajs at ix.netcom.com> wrote:
>What I've come up with is:
>
>L is my list of arbitrary length.
>M= [i for i in range (len(L))]
>
>#thanks to Rainer Deyke's post
>def perms(L):
> if list == [] :
> return [[]]
> return [[list[i] + p for i in range(len(list))\
> for p in perms(list[:i] + list[i+1:])]
>
>def removedups(t):
> for p in t:
> m=copy.copy(p)
> m.reverse()
> if m in t:
> t.remove(m)
>
>def drawcurve(t):
> #t is M or a slice of M
> perm=perms(t)
> removedups(perm)
> for i in range(len(perm)):
> cp=[L[j] for j in perm[i]]
> BezierCurve(cp)
>
>It seems to work.
>
>But I wonder if there is a significantly more
>efficient solution
Assuming that the list of of numbers, and every element in the
list is different, a quick way to test for reversals is to disallow
all lists where the first element is greater than the last one;
this means that you get exactly one of each pair.
--
*** Philip Hunt *** philh at comuno.freeserve.co.uk ***
More information about the Python-list
mailing list