Re: Unyeilding a permutation generator

2008-11-04 Thread Jorgen Grahn
On 3 Nov 2008 22:13:42 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Mon, 03 Nov 2008 21:09:58 +, Jorgen Grahn wrote: > >> Why multi-threading? I see no concurrency in the original algorithm. >> There is, in my mind, nothing concurrent about 'yield'. > > No "real" concurrency b

Re: Unyeilding a permutation generator

2008-11-04 Thread Gerard Flanagan
On Nov 3, 11:45 pm, [EMAIL PROTECTED] wrote: > > Thats interesting code but seems to give a different output, > suggesting thet the underlying algorithm is different. > Ignoring linebreaks and case, the original code gives: > abcd bacd bcad bcda acbd cabd cbad cbda acdb cadb cdab cdba abdc badc > b

Re: Unyeilding a permutation generator

2008-11-04 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: [...] > Thats interesting code but seems to give a different output, > suggesting thet the underlying algorithm is different. Yes. Yours takes the first element out of the list and inserts it in every position of all the permutations of the list without the first element

Re: Unyeilding a permutation generator

2008-11-04 Thread sillyhat
On 2 Nov, 22:03, Carsten Haese <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Anyway what I want to do is experiment with code similar to this (i.e. > > same algorithm and keep the recursion) in other languages, > > particularly vbscript and wondered what it would look like if it was > >

Re: Unyeilding a permutation generator

2008-11-03 Thread sillyhat
On Nov 3, 4:24 pm, Michele Simionato <[EMAIL PROTECTED]> wrote: > On Nov 2, 10:34 pm, [EMAIL PROTECTED] wrote: > > > Anyway what I want to do is experiment with code similar to this (i.e. > > same algorithm and keep the recursion) in other languages, > > particularly vbscript and wondered what it w

Re: Unyeilding a permutation generator

2008-11-03 Thread Aaron Brady
On Nov 3, 4:13 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Mon, 03 Nov 2008 21:09:58 +, Jorgen Grahn wrote: > > Why multi-threading?  I see no concurrency in the original algorithm. > > There is, in my mind, nothing concurrent about 'yield'. > > No "real" concurrency but a gene

Re: Unyeilding a permutation generator

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Nov 2008 21:09:58 +, Jorgen Grahn wrote: > Why multi-threading? I see no concurrency in the original algorithm. > There is, in my mind, nothing concurrent about 'yield'. No "real" concurrency but a generator can be seen as independent thread of code where the generator code is al

Re: Unyeilding a permutation generator

2008-11-03 Thread Jorgen Grahn
On Sun, 2 Nov 2008 14:09:01 -0800 (PST), Aaron Brady <[EMAIL PROTECTED]> wrote: > On Nov 2, 3:34 pm, [EMAIL PROTECTED] wrote: ... >> for x in  all_permx("ABCD"): >>   print x ... > I think multi-threading is the "truest" to the original. You might > develop a framework to set events when particula

Re: Unyeilding a permutation generator

2008-11-03 Thread Michele Simionato
On Nov 2, 10:34 pm, [EMAIL PROTECTED] wrote: > Anyway what I want to do is experiment with code similar to this (i.e. > same algorithm and keep the recursion) in other languages, > particularly vbscript and wondered what it would look like if it was > rewritten to NOT use the yield statement - or a

Re: Unyeilding a permutation generator

2008-11-03 Thread Terry Reedy
Steve Holden wrote: [EMAIL PROTECTED] wrote: Anyway what I want to do is experiment with code similar to this (i.e. same algorithm and keep the recursion) in other languages, particularly vbscript and wondered what it would look like if it was rewritten to NOT use the yield statement - or at l

Re: Unyeilding a permutation generator

2008-11-02 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Hello, can someone please help. > > I found the following code at http://code.activestate.com/recipes/252178/ > > def all_perms(str): > if len(str) <=1: > yield str > else: > for perm in all_perms(str[1:]): > for i in range(len(perm)+

Re: Unyeilding a permutation generator

2008-11-02 Thread Aaron Brady
On Nov 2, 3:34 pm, [EMAIL PROTECTED] wrote: > Hello, can someone please help. > > I found the following code athttp://code.activestate.com/recipes/252178/ > > def all_perms(str): >     if len(str) <=1: >         yield str >     else: >         for perm in all_perms(str[1:]): >             for i in

Re: Unyeilding a permutation generator

2008-11-02 Thread Carsten Haese
[EMAIL PROTECTED] wrote: > Anyway what I want to do is experiment with code similar to this (i.e. > same algorithm and keep the recursion) in other languages, > particularly vbscript and wondered what it would look like if it was > rewritten to NOT use the yield statement An obvious (though memory

Re: Unyeilding a permutation generator

2008-11-02 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Anyway what I want to do is experiment with code similar to this (i.e. > same algorithm and keep the recursion) in other languages, > particularly vbscript and wondered what it would look like if it was > rewritten to NOT use the yield statement - Without the yield sta

Unyeilding a permutation generator

2008-11-02 Thread sillyhat
Hello, can someone please help. I found the following code at http://code.activestate.com/recipes/252178/ def all_perms(str): if len(str) <=1: yield str else: for perm in all_perms(str[1:]): for i in range(len(perm)+1): #nb str[0:1] works in bot

Re: Permutation Generator

2005-08-15 Thread Gerard Flanagan
Talin wrote: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head = lst[:1] > for x in permute( lst[1:] ): >

Re: Permutation Generator

2005-08-15 Thread Tom Anderson
On Mon, 15 Aug 2005, Matt Hammond wrote: > Just satisfied my curiosity wrt this problem, so I might as well share :-) > def permute(list): How about: def permutation(l, i): "Makes the ith permutation of the sequence l." # leave out the reverses if you don't care about the or

Re: Permutation Generator

2005-08-15 Thread Matt Hammond
Just satisfied my curiosity wrt this problem, so I might as well share :-) >>> def permute(list): ... if len(list) <= 1: ... yield list ... else: ... for i in xrange(0,len(list)): ... for tail in permute( list[:i] + list[i+1:] ): ... yield [ list

Re: Permutation Generator

2005-08-14 Thread David Isaac
nd Permutations" - 2005 Can you elaborate a bit on what you mean? Given a list of unique elements, it is easy enough to produce a complete permutation generator in Python, in the sense that it yields every possible permuation. (See my previous post.) So you must mean something else? Che

Re: Permutation Generator

2005-08-14 Thread Casey Hawthorne
It's hard to make "complete" permutation generators, Knuth has a whole fascicle on it - "The Art of Computer Programming - Volume 4 Fascicle 2 - Generating All Tuples and Permutations" - 2005 -- Regards, Casey -- http://mail.python.org/mailman/listinfo/python-list

Re: Permutation Generator

2005-08-14 Thread Jack Diederich
On Fri, Aug 12, 2005 at 03:48:38PM -0400, Michael J. Fromberger wrote: > In article <[EMAIL PROTECTED]>, > Talin <[EMAIL PROTECTED]> wrote: > > > I'm sure I am not the first person to do this, but I wanted to share > > this: a generator which returns all permutations of a list: > > You're right

Re: Permutation Generator

2005-08-13 Thread Jim Washington
On Fri, 12 Aug 2005 12:39:08 -0700, Talin wrote: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head = lst[:1] >

Re: Permutation Generator

2005-08-13 Thread David Isaac
"Talin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I wanted to share > this: a generator which returns all permutations of a list: Try this instead: def permuteg(lst): return ([lst[i]]+x for i in range(len(lst)) for x in permute(lst[:i]+lst[i+1:])) \ or [[]

Re: Permutation Generator

2005-08-12 Thread Paul Rubin
Talin <[EMAIL PROTECTED]> writes: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head = lst[:1] > for x in permu

Re: Permutation Generator

2005-08-12 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>, Talin <[EMAIL PROTECTED]> wrote: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head

Permutation Generator

2005-08-12 Thread Talin
I'm sure I am not the first person to do this, but I wanted to share this: a generator which returns all permutations of a list: def permute( lst ): if len( lst ) == 1: yield lst else: head = lst[:1] for x in permute( lst[1:] ): yield head + x