NYCPHP Meetup

NYPHP.org

[nycphp-talk] mathematical dilemma

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


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
>_______________________________________________
>New York PHP Talk
>Supporting AMP Technology (Apache/MySQL/PHP)
>http://lists.nyphp.org/mailman/listinfo/talk
>http://www.newyorkphp.org
>
>  
>
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.....



More information about the talk mailing list