Previous Up Next

6.5.26  Listing all compositions of an integer into k parts: icomp

A composition of a positive integer n is an ordered set of non-negative integers which sum to n. For example, three compositions of 4 are

     
  4= 1 + 3          
4= 3 + 1         
4= 1 + 1 + 2          

These compositions have two, two and three elements, respectively. The icomp command finds all compositions of an integer with a given number of elements.


Examples.


Previous Up Next