This decision is repeated through all combinations and returns those whose amounts are close enough to the target amount.
Here is a beautiful interface method that allows you to specify a work list, a target amount, and how to close amounts:
public List<List<Work>> GetCombinations(List<Work> workList, double targetSum, double threshhold) { return GetCombinations(0, new List<Work>(), workList, targetSum - threshhold, targetSum + threshhold); }
Here is a recursive method that does all the work:
private List<List<Work>> GetCombinations(double currentSum, List<Work> currentWorks, List<Work> remainingWorks, double minSum, double maxSum) {
This line will receive combinations that add up to 7 +/- 1:
GetCombinations(workToDo, 7, 1);
source share