dimanche 4 janvier 2015

Algorithm to find the closest summation of elements in a list to a given number


Say I have a list {1,3,7,2,11,8,2} and I want to take x elements from the list and get the value 15.5.


Is there an algorithm that would give me x elements in a list that, when added together, get nearest to this given value?


There is no preferred amount of elements, I just want to get as close to the given as possible.


I plan on implementing this algorithm in Swift (Object Oriented) if that makes any difference.





Aucun commentaire:

Enregistrer un commentaire