Partition function by jamesaxl

L=[]\x0d
def p(n)\x0d
return 0 if n < 0\x0d
return 1 if n==0\x0d
return L[n] if L[n]\x0d
s=0\x0d
(1..n).each do |k|\x0d
s+=((-1)**(k+1))*(p(n-(k*(3*k-1))/2)+p(n-(k*(3*k+1))/2))\x0d
L[n]=s\x0d
end\x0d
s\x0d
end\x0d
(1..100).each do |i|\x0d
puts"p(#{i})=#{p(i)}"\x0d
end

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page