http://www.perlmonks.org?node_id=386542


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

This node falls below the community's threshold of quality. You may see it by logging in.
  • 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 (Patriarch) 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
    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.