Am 20.12.2015 um 13:42 schrieb simdax <simoncornaz@xxxxxxxxx>: Hello, The python code does something different from SC's built-in method 'partitions' ! The latter gives out *ordered partitions* in mathematical sense wheras the python code only regards *unordered partitions* in mathematical sense - simpler task, shorter code. There might a confusion about this as in the implementation we have ordered collections (arrays) in both cases and when results are additionally ascending (ordered numbers) they represent the *unordered* partition in mathematical sense, where order doesn't count. But of course you can also write this recursively in SC (I take a recursion start of 1 instead of 0 here, as it's more comfortable): ~p = { |n| var ps; (n==1).if { [[1]] }{ ps = ~p.(n-1).copy; ps.collect([1]++_) ++ ( ps.select { |p| (p.size<2) or: { p[1]>p[0] } } .collect { |p| [p[0]+1] ++ p[1..] } ) } } ~p.(5) The code in the miSCellaneous example with Functions g and h additionally regards ordering and size of the partition, which, when summing over all sizes results in finding all ordered partitions. Regards Daniel ----------------------------- www.daniel-mayer.at ----------------------------- |