in reply to
Generator of integer partitionts of n
And my take (this just prints things out; it would be easy enough to accumulate them into an array or whatever):
#!/usr/bin/perl
part(shift, []);
# Print all partitions of $n using numbers no greater
# than the last element of $sofar
sub part {
my ($n, $sofar) = @_;
if ($n == 0) {
print join(" ", @$sofar), "\n";
return;
}
my $max = @$sofar ? $sofar->[-1] : $n;
my $to = ($max > $n) ? $n : $max;
for (reverse 1 .. $to) {
part($n - $_, [ @$sofar, $_ ]);
}
}