-
-
Save Vusys/3a701401e664ad92ef30cb4f418eb1de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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