3 ms·
I also wrote a simulation, in PHP, when I first encountered this problem. <?php $wins = 0; for ($i = 0; $i < 1000; $i ++) { $car = mt_rand(0, 2);
by hypertele-Xii 5y ago
I also wrote a simulation, in PHP, when I first encountered this problem.
<?php
$wins = 0;
for ($i = 0; $i < 1000; $i ++)
{
$car = mt_rand(0, 2);
$choose = mt_rand(0, 2);
if ($choose == $car) $wins ++;
}
echo "stay: " . ($wins / 1000 * 100) . "%<br />";
// switch
$wins = 0;
for ($i = 0; $i < 1000; $i ++)
{
$car = mt_rand(0, 2);
$choose = mt_rand(0, 2);
if ($choose != $car) $wins ++;
}
echo "switch: " . ($wins / 1000 * 100) . "%";