Skip to content

Instantly share code, notes, and snippets.

@anicholson
Created February 11, 2013 06:06
Show Gist options
  • Save anicholson/4752949 to your computer and use it in GitHub Desktop.
Save anicholson/4752949 to your computer and use it in GitHub Desktop.
<?php
function newBenefit($oldBenefit, $quality, $squares_eaten) {
if($squares_eaten > 5) {
return -1.1 * abs($oldBenefit);
} else if($quality == 'cadbury') {
return $oldBenefit * 0.8;
} else {
return $oldBenefit * 0.95;
}
}
function eatChocolate($quality, $oldProductivity) {
static $cumulativeBenefit = 1;
static $squares_eaten = 0;
static $qualityMap = array('cadbury' => 1.05, 'lindt' => 1.10, 'xocolatl' => 1.25);
$cumulativeBenefit = newBenefit($cumulativeBenefit, $quality, $squares_eaten);
$squares_eaten++;
return $oldProductivity * (1 + ($qualityMap[$quality] * $cumulativeBenefit));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment