Дмитрий Рыбас on Thu, 18 Jul 2019 16:31:32 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Help understanding generating functions, (partitioning n into k parts)


Mike,

Thanks to user mihaild on russian scientific forum dxdy.ru , here is the best (so far), iterative (non-recursive), low-memory (one vector of lenght n) algorithm for partitions function p(n,k) calculation:

pnk(n,k)=
{
my(M=vector(n),res=0);
M[1]=1;
for(i=1,k,
  for(j=1,n-2*i+1,
     M[i+j]+=M[j]);
  res+=M[n-i+1]);
return(res);
}


Try it!

Regards,
Dmitry.