|
|
|
Your skill will accomplish what the force of many cannot |
|
| PerlMonks |
Re: Generator of integer partitionts of nby blokhead (Monsignor) |
| on Aug 28, 2004 at 02:59 UTC ( [id://386571]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
Sloane's Integer Sequences gives the number for partitions of N for many values of N. Here's one using an iterator. Since the number of partitions of N grows exponentially with N, it might be best to not have the entire set of partitions in memory. This is based off the algorithm outlined here. This returns partitions in decreasing lexicographic order. Cheers! Update: Just for fun, here's code for iterating over all partitions of a set (also inspired from the article linked above): The internal order of parts is not significant. The parts are returned in ascending order of their smallest element. If the input set has duplicates, so will the output. I'd have to think about how to do this for multisets... Hey, this is fun! ;) blokhead
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||