Ask Your Question

Revision history [back]

You can iterate over the combinations with a for loop and then compute the sum of the elements as follows:

sage: for i in Combinations([1,2,3,4,5],3): 
....:     print(i, sum(i)) 
....:                                                                                                                                                                                                        
[1, 2, 3] 6
[1, 2, 4] 7
[1, 2, 5] 8
[1, 3, 4] 8
[1, 3, 5] 9
[1, 4, 5] 10
[2, 3, 4] 9
[2, 3, 5] 10
[2, 4, 5] 11
[3, 4, 5] 12