From: Brian Candler Date: 2008-11-05T00:58:07+09:00 Subject: Re: Combination of numbers in an array that add up to x Hae Lee wrote: > Objective: Find list of values in an array that adds up to a specific > sum. > - > I have a list of values in an array: > [2429.63, 497.87, 51.96, 59.43, 138.4, 66.22, 28.74, 1.75, 2075.13, > 556.14, 112.56, 116.5, 84.41, 55.97, 139.07, 24.46] > > I want to find a combination among these numbers that adds up to a total > sum of: > 3435.78 > > I was hoping a one-liner in irb would do the trick but I haven't found a > method, etc. that will help me do this. Thoughts regarding? Google "Knapsack problem" It may be easier if your multiply your numbers up by 100 so you get integers. -- Posted via http://www.ruby-forum.com/.