<?php 
    
include 'page_include.php';
    
$page = new Page('eric');
    
$changet '';
    
$changef '';
    if(isset(
$_POST) && isset($_POST['change'])) {
        
$changet = ($_POST['change'] == 'true') ? 'checked' '';
        
$changef = ($_POST['change'] == 'false') ? 'checked' '';
    }
?>
<?php $page
->print_header('Monty Hall Problem Simulator'); ?>
<p>Ever heard of the Monty Hall problem (<a href="http://en.wikipedia.org/wiki/Monty_Hall_problem">Wikipedia</a>)?</p>
<blockquote cite="http://en.wikipedia.org/wiki/Monty_Hall_problem"><p>
    Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick 
    a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to 
    you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
</p></blockquote>
<p>This php script (<a href="monty.phps">source</a>) reveals the truth!</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label><input type="radio" name="change" id="changet" value="true" <?php echo $changet?>>Change door</label>
<label><input type="radio" name="change" id="changef" value="false" <?php echo $changef?>>Keep first choice</label>
<input type="submit" value="Simulate" />
</form>

<?php
    
if(isset($_POST) && isset($_POST['change'])) {
        
$change = ($_POST['change']=="true");
        
$count 0;
        for(
$i 0$i 10000$i++) {
            
$arr = array(1,2,3);
            
shuffle($arr);
            
            
$goata array_pop($arr);
            
$goatb array_pop($arr);
            
$car array_pop($arr);
            
            
$player rand(1,3);
            
            
$host = ($player == $goata) ? $goatb $goata;
            
            if(
$change) {
                do
                    
$playertwo rand(1,3);
                while(
$playertwo == $host || $playertwo == $player);
            } else
                
$playertwo $player;
            
            if(
$playertwo == $car)
                
$count++;
        }
        echo 
"<p>Player won $count/$i simulations.</p>";
    }
?>
<a href="/">Home</a>
<?php $page->finish_html(); ?>