1 | initial version |
If the order of a
, b
, etc. matters:
sage: IntegerVectors(8, 5)
Integer vectors of length 5 that sum to 8
sage: list(IntegerVectors(8, 5))
[[8, 0, 0, 0, 0],
[7, 1, 0, 0, 0],
[7, 0, 1, 0, 0],
[7, 0, 0, 1, 0],
[7, 0, 0, 0, 1],
[6, 2, 0, 0, 0],
[6, 1, 1, 0, 0],
[6, 1, 0, 1, 0],
[6, 1, 0, 0, 1],
...
If you don't care about the order:
sage: Partitions(8, max_length=5)
Partitions of the integer 8 satisfying constraints max_length=5
sage: list(Partitions(8, max_length=5))
[[8],
[7, 1],
[6, 2],
[6, 1, 1],
[5, 3],
[5, 2, 1],
[5, 1, 1, 1],
[4, 4],
[4, 3, 1],
[4, 2, 2],
[4, 2, 1, 1],
[4, 1, 1, 1, 1],
[3, 3, 2],
[3, 3, 1, 1],
[3, 2, 2, 1],
[3, 2, 1, 1, 1],
[2, 2, 2, 2],
[2, 2, 2, 1, 1]]