Re: Number Comparisons

From: Date: Mon, 02 Oct 2000 13:16:43 +0000
Subject: Re: Number Comparisons
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-18273@lists.php.net to get a copy of this message
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

« previous php.general (#18273) next »