Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 349
- Office Version
- 2003 or older
- Platform
- Windows
I am trying to generate a function to compute strict integer partition count for a given n. I am referencing the below recursive code.
My recursive code is also attached which is not giving the output for a given n. The expected output is 1, 1, 1, 2, 2, 3, 4, 5, 6, 8 for n=1 to 10.
My recursive code is also attached which is not giving the output for a given n. The expected output is 1, 1, 1, 2, 2, 3, 4, 5, 6, 8 for n=1 to 10.
Rich (BB code):
def partitionsQ(n,d=0):
#http://mathworld.wolfram.com/PartitionFunctionQ.html
#http://reference.wolfram.com/language/ref/PartitionsQ.html
#https://oeis.org/A000009
#https://codegolf.stackexchange.com/a/71945/17547
if n==0: return 1
return sum(partitionsQ(n-k,n-2*k+1) for k in range(1,n-d+1))
VBA Code:
Function partitionsQ(n, Optional d = 0)
Dim k
If n = 0 Then partitionsQ = 1
For k = 1 To n - d + 1
partitionsQ = partitionsQ + partitionsQ(n - k, n - 2 * k + 1)
Next
End Function