I am struggling to think of an algorithm which matches my needs. I have a list of integers in a set, each integer represents a maximum value, the list can contain >= 1 entries. I would like to find all the combinations of integers within these maxima that sum to a given value. For example for a list of 4 maxima = [2, 3, 0, 5] and given value = 5, solutions are: [2, 3, 0, 0] [2, 2, 0, 1] [2, 1, 0, 2] [2, 0, 0, 3] [1, 3, 0, 1] [1, 2, 0, 2] [1, 1, 0, 3] [1, 0, 0, 4] [0, 3, 0, 2] [0, 2, 0, 3] [0, 1, 0, 4] [0, 0, 0, 5] I have found some great algorithms related to this but they only address the combinations of the integers in the list which sum to the given value (i.e. in above example, would generate [2, 3] and [5] but not all the other combinations that I am interested in. I have built a solution (in Swift) that solves this with blunt force (see below), but I am looking for something far more efficient. import UIKit let avail = [2, 3, 0, 5] let sol = [0, 0, 0, 0] var solList = [[...