NYCPHP Meetup

NYPHP.org

[nycphp-talk] mathematical dilemma

inforequest sm11szw02 at sneakemail.com
Thu Sep 9 23:23:16 EDT 2004


inforequest sm11szw02-at-sneakemail.com |nyphp 04/2004| wrote:

> Mitch Pirtle mitch.pirtle-at-gmail.com |nyphp 04/2004| wrote:
>
>> Hi gang,
>>
>> Winner of this one gets a beer at the next meet.
>>
>> Say you have a collection of scores, 536 to be exact.  You need to
>> chop them up into deciles (first 10%, second 10%, etc.)
>>
>> Now, take the score from the median, and add it to the last score in
>> the first decile.  Anything above that score gets 100 points.  Simple
>> enough, right?
>>
>> But what if these scores include positive AND negative integers.  Then
>> 'normal' math gives the wrong result...
>>
>> So if the median is 2, and the last score in the first decile is -10,
>> I get -8.  That also is expected.
>>
>> But if the median is 1, and the last score in the first decile is -7,
>> then I get -6.  I need -8, which is the problem...
>>
>> What is the PHP way(TM) to get this behavior without doing a pile of
>> checks for whether the scores to compare are negative or not?
>>
>> -- Mitch, alarmed that his math skills are so pitiful
>>
> In order to win a beer I offer this quick response before thinking 
> through the details :-)
>
> Offset the scores befoe doing the math, by some constant that is more 
> than the expected abs(max score). the shift is neutral with respect to 
> your comparisons, and can be removed when you have your results.
>
> -=john
>
> PS: now I wil l think through the algo.....



I don't see any more to it, assuming that your scores are ordinal (-10 
is a lower score than -8, which is a lower score than any positive score).

-=john





More information about the talk mailing list