Created
October 31, 2019 21:55
-
-
Save 4lb0/b4c58fec828d8970a81b5f25fef64b65 to your computer and use it in GitHub Desktop.
Probability of get a mana dork with Once Upon a Time
This file contains hidden or 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 | |
$simulations = 1000000; | |
$onTheDraw = 1; | |
$deck = array_merge( | |
array_fill(0, 14, 'Mana Dork'), | |
array_fill(0, 4, 'Once Upon a Time'), | |
array_fill(0, 42, 'Other') | |
); | |
function found($card, $start, $total, $deck) | |
{ | |
for ($i = $start; $i < $start + $total; $i++) { | |
if ($deck[$i] == $card) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function foundManaDork($start, $total, $deck) | |
{ | |
return found('Mana Dork', $start, $total, $deck); | |
} | |
$found = 0; | |
for ($i = 0; $i < $simulations; $i++) { | |
shuffle($deck); | |
if (found('Mana Dork', 0, 7 + $onTheDraw, $deck)) { | |
$found++; | |
} elseif (found('Once Upon a Time', 0, 7 + $onTheDraw, $deck)) { | |
if (found('Mana Dork', 7 + $onTheDraw, 5, $deck)) { | |
$found++; | |
} | |
} | |
} | |
echo $found/$simulations*100 . "% on the "; | |
echo $onTheDraw ? "draw" : "play"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment