Php (help Me Solve A Proplem Please)

Discussion in 'PHP' started by vagelism, Sep 5, 2008.

  1. #1
    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.
     
    vagelism, Sep 5, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you have an example of what the imported data will look like? or do you mean the data will be input as say

    3/12 , 10/40 etc
     
    JAY6390, Sep 6, 2008 IP
  3. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    By the above example just make sure that the result is equal to or less than 5 times the number of shots. To see if lesser scores are possible is more complex, you would have to run thru all the possible answers given the number of shotsa and then see if they match the results ... but what about misses ???
     
    mallorcahp, Sep 6, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So for example
    <?php
    
    $shot = '4/18';
    $score = explode('/',$shot);
    if($score[0]*5 < $score[1])
    {
        //Value is too high
        echo 'Maximum score for '.$score[0].' shots is '.($score[0] * 5);
        echo '<br />Your score of '.$score[1].' is too high';
    }else{
        //Value is within limits
        echo 'Score '.$score[1].' is within the range of '.($score[0] * 5);
    }
    PHP:
    This will generate
    Score 18 is within the range of 20
    Code (markup):
    ----------------------------------------------------------------------------
    <?php
    
    $shot = '4/27';
    $score = explode('/',$shot);
    if($score[0]*5 < $score[1])
    {
        //Value is too high
        echo 'Maximum score for '.$score[0].' shots is '.($score[0] * 5);
        echo '<br />Your score of '.$score[1].' is too high';
    }else{
        //Value is within limits
        echo 'Score '.$score[1].' is within the range of '.($score[0] * 5);
    }
    PHP:
    This will generate
    Maximum score for 4 shots is 20
    Your score of 27 is too high
    Code (markup):
    Is that what you mean?
     
    JAY6390, Sep 6, 2008 IP
  5. vagelism

    vagelism Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    We do not care at all for the missing bullets.
    The import will be something like 5/25
    or bullets = 5 and score = 25
     
    vagelism, Sep 6, 2008 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm confused. What exactly will your import look like? and what do you want the result to show? give some examples of the input and output expectations
     
    JAY6390, Sep 6, 2008 IP
  7. vagelism

    vagelism Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    OK some examples.

    We put a result of 4 bulletrs 21 score
    the outpout will be something like..."THIS IS A NON VALID SCORE"
    or 3 bullets 10 score "THIS IS A VALID SCORE YOU CAN NOW PROCEED..."

    THANK YOU FOR YOUR HELP.
     
    vagelism, Sep 6, 2008 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    $input = '4 bullets 21 score';
    $pattern = '/^(?P<bullets>\d+)\sbullets?\s(?P<score>\d+)\sscore$/';
    
    if(preg_match($pattern,$input,$out))
    {
        if($out['bullets'] * 5 < $out['score'])
        {
            echo 'THIS IS A NON VALID SCORE';
        }else{
            echo 'THIS IS A VALID SCORE YOU CAN NOW PROCEED...';
        }
    }else{
        echo 'invalid input';
    }
    PHP:
     
    JAY6390, Sep 6, 2008 IP