Consulting

Results 1 to 2 of 2

Thread: Cant count integer partitions by recursive function.

  1. #1

    Cant count integer partitions by recursive function.

    Hi guys I want to calculate the number of integer partitions. So that I use this code
    Function p(m As Integer, n As Integer)
    If m = 1 Or n = 1 Then
    p(m, n) = 1
    Else
    If n > m Then
    p(m, n) = p(m, m)
    Else
    If m = n Then
    p(m, n) = p(m, m - 1) + 1
    Else
    p(m, n) = p(m, n - 1) + p(m - n, n)
    End If
    End If
    End If
    End Function
    Sub Integer_partitions()
    Debug.Print p(5, 5)
    End Sub
    
    

    But I get the error as " Run time error 28 Out of stuck space".
    What's wrong with my code?
    Regards,
    Alex

  2. #2
    VBAX Newbie dangelor's Avatar
    Joined
    Aug 2014
    Location
    Indiana USA
    Posts
    4
    Location
    Possibly...
    Function p(m As Integer, n As Integer)
        If m = 1 Or n = 1 Then
            p = 1
        Else
            If n > m Then
                p = p(m, m)
            Else
                If m = n Then
                    p = p(m, m - 1) + 1
                Else
                    p = p(m, n - 1) + p(m - n, n)
                End If
            End If
        End If
    End Function
    ___________________________________________________________
    If I've been helpful, let me know. If I haven't, let me know that too. -Rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •