sub P { # This is so that we don't go off the deep end with recursion : ) return [1,1] if $_[0]==1&&$_[1]==1; return [1] if $_[0]==1; # If there's only one argument, return a list of lists containing # the argument and it's partitions. if (@_==1) { return [@_], P($_[0]-1,1) # Otherwise return a list of lists containing the arguments and # the partitions of the opposites. } else { return [@_], map({ [@$_, $_[1]] } P($_[0])), map({ [$_[0], @$_] } P($_[1])) } } #### 5 4 1 3 1 1 2 1 1 1 1 1 1 1 1 And many duplicates (which i handle seperately) #### sub u{map{[split//,$_]}sort{$b cmp$a}keys%{{map{my$t=join'',@$_;$t=>1}@_}}}