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.
Method | 24,6 (33649) | 24,7 (100947) | 24,9 (490314) | Comments |
buk update | 83.1 | 18 min | --- | var with rep, test with List::Util::sum |
tye | 0.50 | 1.43 | 7.47 | Alg::Loops |
anon-hack2 | 0.24 | 1.04 | 4.18 | Alg::Comb combinations |
oiskuu2 | 0.35 | 1.01 | 4.30 | Alg::Comb var with rep |
GF1 | 0.31 | 1.06 | 7.04 | GrandFather's first code |
danaj1 | 0.18 | 0.97 | 59.8 | ntheory unique perms of partitions. Ouch on 24,9. |
danaj2-pp | 0.16 | 0.40 | 1.82 | New ntheory forcomp in Perl |
oiskuu1 | 0.13 | 0.35 | 2.61 | Recursive 'solve' code based on GF |
GF2 | 0.08 | 0.13 | 1.02 | GrandFather's second code |
danaj2 | 0.05 | 0.12 | 0.49 | New ntheory forcomp in XS |