Dr. Robert J. Harley on Thu, 12 Feb 2004 18:32:56 +0100


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

Re: Partition code


Why not something like:

bla(n,m,v, i)=n-=m;v=concat(v,m);if(!n,print(v),for(i=1,min(m,n),bla(n,i,v)))
partitions(n, i)=for(i=1,n,bla(n,i,[]))

then:

? partitions(5)
[1, 1, 1, 1, 1]
[2, 1, 1, 1]
[2, 2, 1]
[3, 1, 1]
[3, 2]
[4, 1]
[5]


R