### Re^2: Generator of integer partitionts of n

 on Aug 28, 2004 at 02:49 UTC ( #386542=note: print w/replies, xml ) Need Help??

in reply to Re: Generator of integer partitionts of n
in thread Generator of integer partitionts of n

Thank you sooooooo much , that's Exactly what i was trying to do, but i need to get this output into an array somehow line by line, can you help just a little bit more please ?
• Comment on Re^2: Generator of integer partitionts of n

Replies are listed 'Best First'.
Re^3: Generator of integer partitionts of n
by ikegami (Pope) on Aug 28, 2004 at 06:34 UTC
```my @p;
sub part
{
my (\$a, \$k, \$n, \$t) = @_;
\$n = 2*\$k unless (defined(\$n));
\$t = 0    unless (defined(\$t));
\$p[\$t] = \$k;
push(@\$a, [ @p[1..\$#p] ]) if \$n == \$k;
for (my \$j = \$k<\$n-\$k ? \$k : \$n-\$k; \$j >= 1; \$j--) {
part(\$a, \$j, \$n-\$k, \$t+1);
}
}

my \$integer = ...;
my @a;
part(\@a, \$integer);
print(join(" ", @\$_), "\n") foreach (@a);
Re^3: Generator of integer partitionts of n
by tilly (Archbishop) on Aug 28, 2004 at 17:51 UTC

Depending on what you're doing, you should reconsider your desire to keep this data in an array. As n grows, the data requirements for that array grow rapidly. Once you use up available RAM (which happens sooner than you'd think), you're in trouble.

Changing your flow of control of your actual problem to avoid having to have it all in memory at once will let you calculate several more values of whatever you're trying to calculate.

Create A New User
Node Status?
node history
Node Type: note [id://386542]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-08-19 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (312 votes). Check out past polls.

Notices?