[seqfan] Re: Partitioning the sequence (?)
Olivier Gerard
olivier.gerard at gmail.com
Mon Dec 22 08:19:15 CET 2008
Dear Zak,
You asked for some Mathematica code.
There is of course the Combinatorica standard package but
it doesn't directly answer your request.
So here is a way (probably not the more concise)
to do it with classic primitives of Mathematica,
starting with 0s and 1s as suggested by other
members:
With[{n = 6, baselist = {a, b, c, d, e, f}},
Map[ Take[baselist, #] &,
Map[ Rest at FoldList[Last[#1] + {1, #2} &, {0, 0}, #] &, Map[Length,
Map[Split, Table[IntegerDigits[i, 2, n], {i, 0, 2^(n - 1) -
1}]], {2}]
], {2}]
]
Here n is what you called L, and of course the number
of variants is 2^(n-1), if all the element of the original list
are differents.
Be aware that there several ways to order the compositions
in sublists of a list. My code may not give you what you intended.
If you need to explore a large set, you will also need a way to
generate such a decomposition one at a time (so that you don't
have to store all results at once).
You can do so from this code, by taking the innermost loop out.
Regards,
Olivier
On Sun, Dec 21, 2008 at 21:38, zak seidov <zakseidov at yahoo.com> wrote:
> Dear SeqFans,
>
> I need to part the sequence a,b,c,d...(of length L)
> in all, n, possible ways:
>
>
> in this case L=4 and n=8 (modulo my errs).
>
> My (humble) Qs:
> what is the function n(L) (guess that this is known one...)
> how to code this in Mathematica/PARI/Maple (in order of decreasing preference)
>
More information about the SeqFan
mailing list