Page 1 of 1

PHP (HELP ME SOLVE A PROPLEM PLEASE)

Posted: Sat Sep 06, 2008 1:03 am
by vagelism
Hello to Everyone.

I have a little problem that I try to solve in PHP.
Suppose we have a shooting target which has three circles. The inner one is the most accurate and gives five points for each bullet there. The middle gives four points and the last one , the outer gives three points, we always try to shoot with ten bullets every time. So an example… 2 bullets at the center 1 in the middle and 2 at the outer gives us a result of. 2x5=10 1x4=4 and 2x3=6 total score is 5/20 (5 the total bullets in the target and 20 the actual score).
So I want some code that I will import the result and it will return me if this shooting score is possible. For example (5/26)is not possible since the maximum result is 5c5=25.
Thank you for your help.

Re: PHP (HELP ME SOLVE A PROPLEM PLEASE)

Posted: Sat Sep 06, 2008 2:30 am
by greyhoundcode
You could always try coding the solution yourself, it seems fairly straightforward ... but since I've just woken up and need to kickstart my brain, how about this, which tests against scores that are infeasibly high or low.

Code: Select all

function AssessScore($score)
{
    $score = explode("/",$score);
    
    $rounds = $score[0];
    $points = $score[1];
    
    $minPos = $rounds * 3;
    $maxPos = $rounds * 5;
    
    if (($points >= $minPos) && ($points <=$maxPos))
    {           
        return true;
    }
 
    return false;
}
Where the argument passed takes the form of a string "rounds_fired/total_score" so you would test against AssessScore("5/25")