Tricky algebra/math

I’m trying to figure out this.

A golfplayer is playing a round of golf with handicap, lets say 27,4. If the player is playing to his handicap he makes 36 points. If he makes more than 36 he should be regulated to a new handicap. But as better he gets the regfulation gets smaller. Let me show an example.

Group Handicap Regulation pr. bonus point
1 0-4,4 0,1
2 4,5 - 11,4 0,2
3 11,5 - 18,4 0,3
4 18,5 - 26,4 0,4
5 26,5 - 36,0 0,5
6 37,0 - –> 1,0

Now the player with his current handicap 27,4 is playing a round where he gets 41 points. This would give him 5 “bonus points” which should get deducted from his current handicap using the data above. this should give him a new handicap 25,2.

Is there anyway I could put this into a formel and automatic calculate the players new handicap?

$points = '41';
$bounuspoints = $points - 36;

if($bonuspoints > 0){
	
	// Some kind of form here //
	
}

Hopefully some can help me with this tricky problem, and many thanks in advance…

I’m not understanding your concept of ‘points’.
Golf is a game where lower = better. Why is more points = lower handicap? shouldnt it be less points = lower handicap?

Normally, yes, but in this case its something called “Stableford Points”. Here you get 2 points for a “par” according to your handicap, 3 points for a birdie, etc. etc…

The problem is still the same… Cant figure out to make this formula… Please help :expressionless:

I think i’m slightly understanding after staring at it for a while, something like this…


$handicap = 27.5;
$boundaries = array(4.4,11.4,18.4,26.4,36,0);
$modifiers = array(0.1,0.2,0.3,0.4,0.5,1);
if($bonuspoints > 0) {
  $i = 0;
  while($handicap <= $boundaries[$i]) {
    $i++;
  }
  $handicap -= $bonuspoints * $modifiers[$i];
}

Er… wait. Make that 100000 a 0. Meant to end the condition, not continue it.

Well, might be on the right track, but tested it and it seems like it only deduct 0.5 once, and what it should actually do is deduct 0.5 x 2 and 0.4 x 3. Cant seem to see where it goes wrong?

$points = 41; 
$bonuspoints = $points - 36; 

$handicap = 27.5;
$boundaries = array(4.4,11.4,18.4,26.4,36,0);
$modifiers = array(0.1,0.2,0.3,0.4,0.5,1);
if($bonuspoints > 0) {
  $i = 0;
  while($handicap <= $boundaries[$i]) {
    $i++;
  }
  $handicap -= $bonuspoints * $modifiers[$i];
}

echo 'New Handicap: '.$handicap;

oh so you want it to change mid-step. That makes sense…
okay, so… do this:


if($bonuspoints > 0) {

becomes:


while($bonuspoints > 0) {

and change

  $handicap -= $bonuspoints * $modifiers[$i]; 

into

   $handicap -= $modifiers[$i]; 
$bonuspoints--;

Well… Still the same. The outcome is 27 and should be 25,2. What about looping through the script 5 times ($bonuspoints) and for each loop get an temperary handicap… Just an idea… Not sure how to though?

Also… Noticed that it deducts 0.5 no matter what base handicap the user has… e.g. 7.3?

I corrected the wrong way lol.

The 0 SHOULD have been a 100000, but the <= should have been a >=.

$boundaries = array(4.4,11.4,18.4,26.4,36,1000000); 
$modifiers = array(0.1,0.2,0.3,0.4,0.5,1); 
while($bonuspoints > 0) { 
  $i = 0; 
  while($handicap >= $boundaries[$i]) { 
    $i++; 
  } 
  $handicap -= $modifiers[$i]; 
  $bonuspoints--;
} 

And YES!!! Thanks alot man. Your the best. It works like a charm…