# Thread: Cant count integer partitions by recursive function.

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  Reply With Quote

2. 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```  Reply With Quote

#### Posting Permissions

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