Say I have one number 'n' and a table of numbers. I want to choose up to four of the numbers in the table, and the sum of those four will be the closest possible match to n. Given length 'L' of the table, the number of combinations it has to go through is (6*L + 11*L^2 + 6*L^3 + L^4)/24.
ex. Say I have the variable
n = 100
and the set of numbers
t = {86, 23, 19, 8, 42, 12, 49}
Given this list, the closest combination of four to n is 49 + 23 + 19 + 8 = 99.
What is the optimal way of doing this with the least possible number of calculations?