The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





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 


Messages In This Thread
(50G) Partition of Integer N in M Parts - Gerald H - 10-09-2016 02:47 PM



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