#!/usr/bin/perl

#
# The Polya urn model
# We start with an urn which contains one white ball and one black ball.
# Every minute we choose a ball at random from the urn, then replace this
# ball and add one more of the same color. 
#
# Version one: one game, output number of white and black balls
#

# Set up variables
$w = 1;			# Number of white balls
$t = 10000;		# Number of total marbles to have in urn

for($i = 2; $i < $t; $i++) {
  $w += (rand($i) < $w);
}

print "Number of white balls: $w\n";
$b = $t - $w;
print "Number of black balls: $b\n";
