max = 200
max=max+2 ### due to the later code, it got offset by 2
P = [0]*max ### make a list of zeros, length max
P[0] = 1
P[1] = 1
print 0,":", P[0] ### print value for n = 0,1
print 1,":", P[1]
Psign = [0]*max ### make a list the same length as P, to store the signs
### apply Euler's pentagonal numbers formula
k = 1
index= k*(3*k-1)/2
while index <=max:
Psign[index] = (-1)**k
index = k*(3*k+1)/2
if index<=max:
Psign[index] = (-1)**k
k=k+1
index = k*(3*k-1)/2
for n in range(1,max+1):
n=n+1
P[n] = 0
for i in range(0,n+1):
i=i+1
P[n] = P[n] - P[n-i]*Psign[i]
print n,":",P[n]
So I've got this code which can gives answer to the Number of Partitions of n (up to 200 at the moment). However, since I adapted the code from here which was written in Mathematica. I'm not quite sure about the later part. Somehow this part messes up with my limit. So if I want to produce number of partitions for 25, I must set my max variable to 27.
I really hope someone can help me correct this
Cheers,
Alex