That's the hard part, isn't it.
roundup and rounddown can be used to find the two numbers that will be present: roundup(4.67,0)=5 rounddown(4.67,0)=4.
I haven't tested this rigorously, but I think you can use the fractional result (the remainder if you remember from elementary math) to tell you how many of the roundup values you need. the remainder can be returned using the mod function: mod(14,3)=2, so you need two 5's and one 4.
In another case, use the five numbers: 1,2,3,4,6
sum(1,2,3,4,6)=16
count(1,2,3,4,6)=5
roundup(average(1,2,3,4,6),0)=4
rounddown(average(1,2,3,4,6),0)=3
mod(sum(1,2,3,4,6),count(1,2,3,4,6))=1
so you need one 4 and (5-1)=four 3's.
The algorithm should work in the other cases where average is an integer, because roundup and rounddown will return the same value, and mod will return 0.
At this point, do you need a routine to populate 5 cells with 3's and 4's, or will it be enough to say that the answer is one 4 and four 3's?
Bookmarks