0) { $firstVisit = false; } $trials = 1000000; $payout1 = 0; $chance1 = 50; // editable $payout2 = 1; $chance2 = 25; // editable $payout3 = 2; $chance3 = 15; // editable $payout4 = 3; $chance4 = 9; // editable $payout5 = 50; // editable $chance5 = 1; $alert = ""; if (array_key_exists('chance1', $_POST) && is_numeric($_POST['chance1'])) { if ( $_POST['chance1'] < 0) { $alert .= "Alert: Chance of payout 1 was less than 0%.
\n"; } elseif ($_POST['chance1'] > 100) { $alert .= "Alert: Chance of payout 1 was greater than 100%.
\n"; } $chance1 = max(0, $_POST['chance1']); $chance1 = min($chance1, 100); } if (array_key_exists('chance2', $_POST) && is_numeric($_POST['chance2'])) { if ( $_POST['chance2'] < 0) { $alert .= "Alert: Chance of payout 2 was less than 0%.
\n"; } elseif ($_POST['chance2'] > 100) { $alert .= "Alert: Chance of payout 2 was greater than 100%.
\n"; } $chance2 = max(0, $_POST['chance2']); $chance2 = min($chance2, 100); } if (array_key_exists('chance3', $_POST) && is_numeric($_POST['chance3'])) { if ( $_POST['chance3'] < 0) { $alert .= "Alert: Chance of payout 3 was less than 0%.
\n"; } elseif ($_POST['chance3'] > 100) { $alert .= "Alert: Chance of payout 3 was greater than 100%.
\n"; } $chance3 = max(0, $_POST['chance3']); $chance3 = min($chance3, 100); } if (array_key_exists('chance4', $_POST) && is_numeric($_POST['chance4'])) { if ( $_POST['chance4'] < 0) { $alert .= "Alert: Chance of payout 4 was less than 0%.
\n"; } elseif ($_POST['chance4'] > 100) { $alert .= "Alert: Chance of payout 4 was greater than 100%.
\n"; } $chance4 = max(0, $_POST['chance4']); $chance4 = min($chance4, 100); } if (array_key_exists('payout5', $_POST) && is_numeric($_POST['payout5'])) { $payout5 = max(1, $_POST['payout5']); } // confirm that the probabilities add up to 100% $total = $chance1 + $chance2 + $chance3 + $chance4 + $chance5; // under 100% if ($total < 100) { $alert .= "Alert: Total chance was less than 100%. Increased Payout 1 chance to fix the problem.
\n"; // increase chance1 to match $chance1 = 100 - ($chance2 + $chance3 + $chance4 + $chance5); } // above 100% elseif ($total > 100) { $alert .= "Alert: Total chance exceeded 100%. Decreased payouts to fix the problem.
\n"; // decrease chance 1 to match $chance1 = 100 - ($chance2 + $chance3 + $chance4 + $chance5); if ($chance1 < 0) { // decrease chance2 as well $chance2 += $chance1; $chance1 = 0; if ($chance2 < 0) { $chance3 += $chance2; $chance2 = 0; if ($chance3 < 0) { $chance4 = 100 - $chance5; $chance3 = 0; } } } } $totalProfit = 0; ?>

Puzzle 3

You are an assistant game designer working on a slot machine game.
The lead designer tells you to balance the game so that players lose 2% of their bet, on average.
Note: Not all of the numbers below are editable.

Alert: Some math error. Please e-mail Ira.
\n"; } } echo $alert; echo "After ".$trials." tries, the change in money was "; echo round($totalProfit/$trials, 3)." bets.
\n"; echo "
\n"; } ?>
Option Value (bets) Chance (%)
Payout 1
Payout 2
Payout 3
Payout 4
Payout 5

Note: A value of 0 means the player loses his/her bet.
Note: A value of 1 means the player gets back his/her bet, neither winning nor losing.
Note: A value of 2 means the player wins double his/her bet.


Back to Puzzle List