![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: How to restrict partitionsby danaj (Friar) |
on Oct 04, 2014 at 06:47 UTC ( [id://1102806]=note: print w/replies, xml ) | Need Help?? |
Rather late, but I believe this works:
forpart is a partitions iterator similar to Pari/GP 2.6.1+, either unrestricted or with min/max/exact number of elements / size of elements. Pari/GP has some better optimizations, but even so, restricting the number of elements inside the XS code is a big win. For cases where the sum and number of desired partitions gets large it helps to be a little smarter. Since we want unique elements, we know sequences like ... 1 1 1 1 1 won't work. The minimum sequence ends with ... 5 4 3 2 1, so we can find out the largest allowed element: I think this is pretty straightforward to use and quite fast for most cases. As the sum goes up much over 100 this can still get out of control (Pari has the same issue). tye's Algorithm::Loops solution is better at weeding out non-uniques early in this case.
In Section
Seekers of Perl Wisdom
|
|