+ Reply to Thread
Results 1 to 6 of 6

Equalising numbers

  1. #1
    Registered User
    Join Date
    06-08-2011
    Location
    England
    MS-Off Ver
    Excel 2000
    Posts
    2

    Question Equalising numbers

    I would like to equalise a set of 3 (or maybe more) numbers.

    For example I would like
    6,4,2
    to become
    4,4,4

    or

    9,0,5
    to become
    5,4,5

    or

    0,3,0
    to become
    1,1,1

    If I had 2 numbers the the sum is simple. I'd subtract the lower number from the higher. Then half that number and add it to the lower and subtract from the higher.
    8,6 would become 7,7

    But how can I equalise 3 or more numbers?

    How can I do this?

    Thanks!

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,374

    Re: Equalising numbers

    It looks to me like you are basically trying to take a set of numbers and find the average.

    Average(6,4,2)=4
    average(8,6)=7
    average(0,3,0)=1
    average(9,0,5)=4.67, which you have rounded some up/some down to get 5,4,5, so that the three numbers add up to the same quantity.

    Sound like the right idea?

  3. #3
    Registered User
    Join Date
    06-08-2011
    Location
    England
    MS-Off Ver
    Excel 2000
    Posts
    2

    Re: Equalising numbers

    Yeah it's sort of an average/median I suppose!
    But
    average(9,0,5)=4.67
    What formula would I use to change 9,0,5 to 5,4,5 ???

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Equalising numbers

    Does the order 5,4,5 matter to you, or would you be happy if it was 5,5,4?
    Hope that helps,

    Colin

    RAD Excel Blog

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,374

    Re: Equalising numbers

    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?

  6. #6
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Equalising numbers

    I'm sure some of the maths experts on here will provide a solution that absolutely rocks, but in the meantime I think a generic function to calculate each number in the series would be:
    Please Login or Register  to view this content.
    Where n is the position of the 'equalised' number in the equalised set.
    Due to Double precision, 0.33333' does not necessarily equal 1/3, 0.66666' to 2/3 etc., so revise the function for Excel to this:
    Please Login or Register  to view this content.
    Where the 1/1000 is a small fraction to ensure that the >= is correctly met. Obviously if your sets became much larger then this would fall short.

    Examples up to 7 random numbers in a set in the attached example. Numeric order in the equalised set and negative averages not taken into consideration. For negative averages I think a function (which no doubt can be simplified) would be:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Colin Legg; 06-08-2011 at 07:18 PM. Reason: added comment re negative averages

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1