HP Forums
(48G) Number of Perfect Integer Partitions (also 49G & 50G) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (48G) Number of Perfect Integer Partitions (also 49G & 50G) (/thread-4303.html)



(48G) Number of Perfect Integer Partitions (also 49G & 50G) - Gerald H - 07-05-2015 06:29 PM

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
  ;
;