From: Axel Etzold Date: 2008-11-05T01:21:08+09:00 Subject: Re: Combination of numbers in an array that add up to x -------- Original-Nachricht -------- > Datum: Wed, 5 Nov 2008 00:58:07 +0900 > Von: Brian Candler > An: ruby-talk@ruby-lang.org > Betreff: 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/. Dear Hae, There is Gecoder for combinatorial optimization problems in Ruby : http://gecoder.rubyforge.org/ The numbers must be integers. Best regards, Axel -- "Feel free" - 5 GB Mailbox, 50 FreeSMS/Monat ... Jetzt GMX ProMail testen: http://www.gmx.net/de/go/promail