HP Forums

Full Version: (48G) Number of Perfect Integer Partitions (also 49G & 50G)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For positive integer input the programme returns the number of perfect partitions.

A perfect partition of N allows additive composition of all numbers <= N.

eg

{4 , 1} is not a perfect partition of 5 as you can't make 2 from a sum of the elements.

{1 , 2 , 2} is a perfect partition of 5 as all of 1, 2, 3, 4 & 5 are additively composable from its elements.

Code:

::
  CK1&Dispatch
  BINT1
  ::
    DUP
    %0<
    caseSIZEERR
    %IP
    COERCE
    #1+
    BINT1
    OVER
    NDUPN
    '
    NULLLAM
    SWAP
    NDUPN
    DOBIND
    DUP#1+
    BINT2
    DO
    BINT0
    INDEX@
    DUP
    ONE_DO
    DUPINDEX@
    #/
    DROP
    #0=
    IT
    ::
      SWAPINDEX@
      GETLAM
      #+SWAP
    ;
    LOOP
    PUTLAM
    LOOP
    GETLAM
    ABND
    UNCOERCE
  ;
;
Reference URL's