10-09-2016, 02:47 PM
For stack
N
M
both positive integers the programme returns the number of partitions of N into at most M parts.
For more info see
https://en.wikipedia.org/wiki/Partition_(number_theory)
eg For input
30
19
the programme returns
5465
in 3.9 seconds.
N
M
both positive integers the programme returns the number of partitions of N into at most M parts.
For more info see
https://en.wikipedia.org/wiki/Partition_(number_theory)
eg For input
30
19
the programme returns
5465
in 3.9 seconds.
Code:
::
CK2&Dispatch
2REAL
::
COERCE2
2DUP
#*
#0=
case2drop
BINT0
'
::
DUP#1=
3PICK
#1=
OR
case2drop
BINT1
2DUP
#<
casedrop
::
DUP
1GETLAM
EVAL
;
OVER
#=casedrop
::
DUP#1-
1GETLAM
EVAL
#1+
;
2DUP
#-OVER
1GETLAM
EVAL
3UNROLL
#1-
1GETLAM
EVAL
#+
;
DUP1LAMBIND
EVAL
ABND
FPTR2 ^#>Z
;
;