Quote:
Originally Posted by pdurrant
Sorry, you're not right. The chances of winning by sticking to your original choice and winning by switching to the other remaining cylinder must sum to 1. You have it adding up to 5/6ths.
|
Damnit! I forgot I was programming in perl instead of C, and I used "break" instead of "last" to exit a for loop. It skewed my game results.
Oh well. I fixed it, and it does break even now.
Code:
#!/usr/bin/perl
$win=$lose=0;
$money=1;
for ($i=1; $i<=10;$i++) {
@shell = (0, 1, 2);
$deal = int(rand(3)); # The shell with the coin
splice(@shell,$deal,1); # The empty shells.
$money -= 1; # Player's wager.
$pick = int(rand(3)); # Player's shell choice.
if (int(rand(2))) { # Remove an empty shell that the
$rem=$shell[1]; # ..player hasn't chosen.
if ($pick == $rem) {
$rem=$shell[0];
}
} else {
$rem=$shell[0];
if ($pick == $rem) {
$rem=$shell[1];
}
}
print "Dealer gets $deal. Player picks $pick. Dealer removes $rem.\n";
for ($j=0;$j<3;$j++) { # Change the pick to the other remaing shell.
next if ($pick == $j or $rem == $j);
$pick = $j;
last; # DAMNIT! I used "break;" instead of last!
}
$money -= 1; # Double your bet.
print "Player changes to $pick.\n";
if ($pick == $deal) {
$money += 3; # Winner! Get your 3 coins!
$win++;
print "Player Wins.\n";
} else {
$lose++; # Loser!
print "Player Loses.\n";
}
print "\nGames: $i Wins: $win Losses: $lose Player Money: $money\n\n";
}
Syntax errors will be the death of me. BTW - Thanks, perl for not catching such a basic error...