Your skill will accomplishwhat the force of many cannot PerlMonks

### 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);
[download]```
Re^3: Generator of integer partitionts of n
by tilly (Archbishop) on Aug 28, 2004 at 17:51 UTC
Some random advice for you.

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.

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://386542]
help
Chatterbox?
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-01-19 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How did you see in the new year?

Results (215 votes). Check out past polls.

Notices?