Help for this page

Select Code to Download


  1. 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
    }
    
  2. or download this
    sub partition {
        my ( $m, $n ) = @_;
    ...
        $n ||= $m;
        say partition( $m, $n );
    }
    
  3. or download this
    sub P {
        # Returns strings!
    ...
            printf( "\n = %s", $_ );   
        }
    }
    
  4. 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