Post Reply 
(50G) Partition of Integer N in M Parts
10-09-2016, 02:47 PM (This post was last modified: 06-15-2017 01:40 PM by Gene.)
Post: #1
(50G) Partition of Integer N in M Parts
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.

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
  ;
;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)