I added a forcomp iterator to ntheory, and changed to Kelleher's RuleAsc algorithm from ZS1. The changes to support both compositions and partitions are minimal. This means lexicographic ordering for both (vs. anti-lexico), which I think fits in better with the same ordering for combinations and permutations. It has the same restriction options as partitions (min/max for both length and value). It's on github, not sure when it'll hit CPAN. (update: it's on CPAN now as version 0.56)

Some timings of various solutions on this thread, for larger values. Macbook Pro, Perl 5.22.0. Other sizes may give different results, each solution has different tradeoffs, etc. I thought it was interesting.

Method24,6
(33649)
24,7
(100947)
24,9
(490314)
Comments
buk update83.118 min---var with rep, test with List::Util::sum
tye0.501.437.47Alg::Loops
anon-hack20.241.044.18Alg::Comb combinations
oiskuu20.351.014.30Alg::Comb var with rep
GF10.311.067.04GrandFather's first code
danaj10.180.9759.8ntheory unique perms of partitions. Ouch on 24,9.
danaj2-pp0.160.401.82New ntheory forcomp in Perl
oiskuu10.130.352.61Recursive 'solve' code based on GF
GF20.080.131.02GrandFather's second code
danaj20.050.120.49New ntheory forcomp in XS


In reply to Re: Combinatorics problem. (Updated with more info.) by danaj
in thread Combinatorics problem. (Updated with more info.) by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.