#! perl -slw use strict; sub xp{ [ @$_, 1 ], @$_ > 1 && $_->[ -1 ] < $_->[ -2 ] ? [ @$_[ 0 .. $#$_ -1 ], $_->[ -1 ]+1 ] : () } sub partitions { return unless $_[ 0 ]; map( xp, partitions( $_[ 0 ] - 1 ) ), [ $_[ 0 ] ]; } print "@$_" for partitions $ARGV[ 0 ]; __END__ P:\test>386531 6 1 1 1 1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 3 1 1 1 3 2 1 3 3 4 1 1 4 2 5 1 6