I have searched and read about algorithms for this problem but they don't seem to apply in this case, or were not clear enough.
I have a List<decimal>
of unsigned values where I'm trying to find the element(s) which sum is the closest to a specified value N
The List is of variable size with average of 500 elements. Performance is NOT a priority for this solution.
The implemented method should return a single solution or an empty list if no solution is found.
Existing more than one, pick one with the less elements.
Example:
N = 15.00
Elements = {
0.10, //EDIT: This shouldn't be here
7.00,
7.00,
14.10,
15.90,
}
Solutions = {
0.10 + 7.00 + 7.00, //EDIT: This shouldn't be here
14.10,
15.90,
}
Final Solution = {14.10} // or 15.90