Re: Number Comparisons

From: Date: Mon, 02 Oct 2000 21:18:02 +0000
Subject: Re: Number Comparisons
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-18308@lists.php.net to get a copy of this message
----- Original Message ----- From: "Teodor Cimpoesu" <teo@digiro.net> To: <php-general@lists.php.net> Sent: Monday, October 02, 2000 11:16 PM Subject: Re: [PHP] Number Comparisons > Hi Real! > On Mon, 02 Oct 2000, Real GM Webmaster wrote: > > > Hi, > > > > I have a problem that has had be scratching my head for the last three weeks. > > > > What I need to do is take a number, say 40, and then have a varying number of other integers that I need to find the best fit into the original number. There could be four, give, or 25 numbers that could fit. > > > > For example, using 40 as the basis. > > > > Just say on the flip side I have 20, 9, 7, 5, and 2. > > > > I need to find the sum of these numbers that will end up closest to 40. In this case the numbers that would be returned would be 20, 9, 7 and 2, which equals 38.. 5 would be left over. Any other sum would either push me over the 40 mark or would fall short of the 38. > > > > Any idea on how to do this. Remember, that the number of numbers that will be compared is not static. > > > > Please help me, because I am completely stuck and this is vital to the accuracy of our site. > > > Do you need all the combinations? or just the `longest' as number of > `numbers'? > This pretty looks like a backtracking/greedy algo job. > > -- teodor I just need the combination of numbers that's sum will give me the closest number to the original, which in the example is 40. I also need to know which numbers are left over. Any ideas? Thanks again, Michael

« previous php.general (#18308) next »