[SciPy-User] all unique permutations
Peter Tittmann
ptittmann at gmail.com
Thu Apr 28 20:59:10 EDT 2011
Hi Josef,
Not sure if this is relevant but i've used itertools.permutations (http://docs.python.org/library/itertools.html#itertools.permutations)
Best,
Peter
--
Peter Tittmann
c 707 849 4135
On Thursday, April 28, 2011 at 5:40 PM, josef.pktd at gmail.com wrote:
> On Thu, Apr 28, 2011 at 8:27 PM, <josef.pktd at gmail.com> wrote:
> > is there a copyright on basic algorithms ?
> >
> > from
> > http://www.cut-the-knot.org/do_you_know/AllPerm.shtml
> > I translated
> > 2.Lexicographic order and finding the next permutation
> >
> > into python (because I couldn't get the matlab translation to work)
> >
> > looks useful for some permutation test
> >
> > some examples
> >
> > > > > pprint(list(permit([1,1,1,1,0])))
> > [[0, 1, 1, 1, 1],
> > [1, 0, 1, 1, 1],
> > [1, 1, 0, 1, 1],
> > [1, 1, 1, 0, 1],
> > [1, 1, 1, 1, 0]]
> >
> > > > > for i in permit([1,0,1,0]): print i
> > ...
> > [0, 0, 1, 1]
> > [0, 1, 0, 1]
> > [0, 1, 1, 0]
> > [1, 0, 0, 1]
> > [1, 0, 1, 0]
> > [1, 1, 0, 0]
> >
> > > > > for i in permit([1,0,2,2]): print i
> > ...
> > [0, 1, 2, 2]
> > [0, 2, 1, 2]
> > [0, 2, 2, 1]
> > [1, 0, 2, 2]
> > [1, 2, 0, 2]
> > [1, 2, 2, 0]
> > [2, 0, 1, 2]
> > [2, 0, 2, 1]
> > [2, 1, 0, 2]
> > [2, 1, 2, 0]
> > [2, 2, 0, 1]
> > [2, 2, 1, 0]
> >
> > > > > for i in permit([1,3]): print i
> > ...
> > [1, 3]
> > [3, 1]
> >
> > > > > for i in permit([1,2.3]): print i
> > ...
> > [1, 2.2999999999999998]
> > [2.2999999999999998, 1]
> >
> > > > > for i in permit([1,2.5,3.5]): print i
> > ...
> > [1, 2.5, 3.5]
> > [1, 3.5, 2.5]
> > [2.5, 1, 3.5]
> > [2.5, 3.5, 1]
> > [3.5, 1, 2.5]
> > [3.5, 2.5, 1]
>
> and
>
> > > > for i in permit(['aa','bbb','c','aa']): print i
> ...
> ['aa', 'aa', 'bbb', 'c']
> ['aa', 'aa', 'c', 'bbb']
> ['aa', 'bbb', 'aa', 'c']
> ['aa', 'bbb', 'c', 'aa']
> ['aa', 'c', 'aa', 'bbb']
> ['aa', 'c', 'bbb', 'aa']
> ['bbb', 'aa', 'aa', 'c']
> ['bbb', 'aa', 'c', 'aa']
> ['bbb', 'c', 'aa', 'aa']
> ['c', 'aa', 'aa', 'bbb']
> ['c', 'aa', 'bbb', 'aa']
> ['c', 'bbb', 'aa', 'aa']
>
> >
> > Josef
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110428/7c4ec68f/attachment.html>
More information about the SciPy-User
mailing list