#!/usr/bin/perl

#
# coinflip.pl
# Six coins in a bag, one is a double-headed coin.
# If I pick one at random, and flip four heads in a row,
# what is the probablility that I had chosen the trick coin?
#

# Variables

$c1 = 0;	# Counting variable : trick coins
$c2 = 0;	# Counting variable : regular coins
$t = 10000;	# Trials variable

# Program

for($i = 0; $i < $t; $i++) {
  if(rand(6) < 1) {
    $c1++;
  }
  else {
    if(rand(16) < 1) {
      $c2++;
    }
  }
}

$z = $c1 / ($c1 + $c2);

print "Result: $z\n";

