partitions.frink

// Returns all the partitions of an integer.// NOTE: This class is no longer necessary as Frink now has a built-in// partitions function.// // The algorithm is Algorithm P from Knuth's 7.2.1.4
partitionInteger[n] :=
{
a = new array[] // Array of size n+1
results = new array

a@0 = 0
m = 1
count = 0

// Step P2
a@m = n
q = m - (n==1 ? 1 : 0)

do
{// Step P3... dump the partition.// This would be a good place for a "yield" statement.
results.push[sliceLength[a,1,m]]
count = count + 1