Ejemplo n.º 1
0
$nine4 = cointoss(1, 2);
$nine5 = cointoss(1, 2);
$nine6 = cointoss(1, 2);
$nine7 = cointoss(1, 2);
$nine8 = cointoss(1, 2);
$nine9 = cointoss(1, 2);
echo "{$nine1}";
echo "{$nine2}";
echo "{$nine3}";
echo "{$nine4}";
echo "{$nine5}";
echo "{$nine6}";
echo "{$nine7}";
echo "{$nine8}";
echo "{$nine9}<br>";
echo "<br>";
/*AHHH! I thought str_repeat would make it repeat 
more than once but it doesn't even give me 10...do I really
need to assign a new string name each time???*/
for ($count = 1; $count <= 600; ++$count) {
    $twoheads = cointoss($a, $b);
    if ($count = 5) {
        break;
    }
    echo str_repeat($twoheads, 10);
}
?>


</body>
</html>
Ejemplo n.º 2
0
    $test_array = [];
    $result_array = [];
    do {
        if (mt_rand(1, 2) == 1) {
            array_push($result_array, 1);
            unset($test_array);
            $test_array = [];
        } else {
            array_push($result_array, 2);
            array_push($test_array, 2);
        }
    } while (count($test_array) < $toss);
    return $result_array;
}
echo "We are looking for {$b} heads in a row...<br>";
$result = cointoss($b);
$count = count($result);
// I made a loop that prints the result list until we get the desired result.
foreach ($result as $flip) {
    if ($flip == 1) {
        echo "<img src=http://30.media.tumblr.com/tumblr_l9jgddd49q1qzgcpyo1_500.gif style=width:120px;height:120px>";
    } elseif ($flip == 2) {
        echo "<img src=http://vignette2.wikia.nocookie.net/spartacus/images/5/55/Juliuscaesar.jpg/revision/latest?cb=20130606052819 style=width:90px;height:120px>";
    }
}
echo "<br><p>It took {$count} tosses to land {$b} heads in a row.</p>";
echo "</div>";
?>

</body>
</html>