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