What an interesting problem, but since my php coding skills are
, at best, I will take a mathematical approach. I wrote a similar code for my calculator some time ago, this is how it worked :
sort() the original array of numbers, low to high. => 1 12 12 21 23 23 25 34 43 65 65 74 76
Code:
$n=1
$m= number of the items in the array
if [ "$nth number" + "$mth number" < 100 ]
then
"$nth number" + "$mth number" = $x
$n + 1 = $n
while [ $x + $nth number < 100 ]
x + $nth number = $x
$n + 1 = $n
done
store $mth and the numbers lower than $n as an array
$m - 1 = $m
else
store $mth number alone as an array
$m - 1 = $m
fi
I'm pretty sure there is a better way to do this. I actually used few other wrongs ways in my real code. For example one of them just added first and last numbers and store them as arrays, another added random items to find 90+ arrays groups than it looked for 80+, 70+ and 50+ arrays from remaining numbers. In mine there was also a final part to decide the result generated by which way was the best and a logger to note which way was used. I was planning to connect this to a random number generator and inspect the logs to find which was most effective But my calculator got stolen and I forgot the project.
Please let me know if you find a better way
Bookmarks