Number Comparisons
| From: | Real GM Webmaster | Date: | Mon, 02 Oct 2000 12:28:04 +0000 |
| Subject: | Number Comparisons | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-18264@lists.php.net to get a copy of this message | ||
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.
Thank you in advance,
Michael.