- or download this
P(m,n) = {
1 if m or n = 1,
...
1 + P(m,m-1) if m = n > 1,
P(m,n-1) + P(m-n,n) if m > n > 1
}
- or download this
sub partition {
my ( $m, $n ) = @_;
...
$n ||= $m;
say partition( $m, $n );
}
- or download this
sub P {
# Returns strings!
...
printf( "\n = %s", $_ );
}
}
- or download this
$ partition.pl 7
P(7,7)
...
= 7 + 1 + P(3,1) + P(1,2) + 1 + 1 + P(2,1) + 1 + 1
= 12 + 1 + 1 + 1
= 15