Kay Schluehr:
>[Yes, I have too much time...]
Thank you for your code. If you allow me to, I may put some code
derived from yours back into the rosettacode.org site.
>Here is an evil imperative, non-recursive generator:
I like imperative, non-recursive code :-)
If you count the number of item
Here is an evil imperative, non-recursive generator:
def ncsub(seq):
n = len(seq)
R = xrange(n+1)
for i in xrange(1,2**n):
S = []
nc = False
for j in R:
k = i>>j
if k == 0:
if nc:
yield S
ns some subset of the elements of this sequence,
> in the same order. A continuous subsequence is one in which no
> elements are missing between the first and last elements of the
> subsequence. The task is to enumerate all non-continuous subsequences
> for a given sequence.
>
That'
Bruce Frederiksen:
Your solution is a bit different from what I was thinking about (I was
thinking about a generator function, with yield), but it works.
This line:
> return itertools.chain(
>itertools.imap(lambda ys: x + ys, ncsub(xs, s + p1)),
>nc
equence contains some subset of the elements of this sequence,
> in the same order. A continuous subsequence is one in which no
> elements are missing between the first and last elements of the
> subsequence. The task is to enumerate all non-continuous subsequences
> for a given sequence.
&g
subsequence is one in which no
elements are missing between the first and last elements of the
subsequence. The task is to enumerate all non-continuous subsequences
for a given sequence.
Translating the Scheme code to Python was easy (and I think this is
quite more readable than the Scheme version