Skip to content

Instantly share code, notes, and snippets.

@Vusys

Vusys/bccc48.php Secret

Last active October 26, 2020 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vusys/3a701401e664ad92ef30cb4f418eb1de to your computer and use it in GitHub Desktop.
Save Vusys/3a701401e664ad92ef30cb4f418eb1de to your computer and use it in GitHub Desktop.
<?php
function trick_or_treat($sweets, $children, $range)
{
$hadEnoughSweets = 0;
for ($i = 0; $i < 1000; $i++) {
$availableSweets = $sweets;
$estimatedChildren = random_int($children[0], $children[1]);
for ($u = $estimatedChildren; $u > 0; $u--) {
$availableSweets -= random_int($range[0], $range[1]);
}
$hadEnoughSweets += $availableSweets >= 0;
}
return number_format($hadEnoughSweets / 10, 1);
}
print trick_or_treat(150, [20, 25], [5, 10]) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment