# factorial function fac(n) return (1..n).prod() end # raising factorial function rf(x,n) n.prod(|k| x+k) end # falling factorial function ff(x,n) n.prod(|k| x-k) end # binomial coefficient function bc(n,k) if k<0 or k>n return 0 elif k==0 or k==n return 1 else k=min(k,n-k) y=1 for i in 0..k-1 y = y*(n-i)//(i+1) end return y end end # multinomial coefficient function mc(k) return len(k).prod(|i| bc(i.sum(|j| k[j]),k[i])) end # finite difference function Delta(n,f,x,h) return (fn|x| f(x+h)-f(x) end^n)(x) end begin public pf m = {} function partition(n,k) if nk*max return [] elif n==k*max return [[max]*k] elif k==1 return [[n]] else a=[] for x in 1..min(max,n-1) for t in part(n-x,k-1,x) a.push(t+[x]) end end return a end end function partitions(n,k) part(n,k,n) end end