Problem 6 of Monte Carlo solutions to Fifty Challenging Problems...

(This is another part of the Fifty Problems series, a set of example applications of Monte Carlo methods. In each post, I present source code which answers a probabilistic question using simulated models of the underlying system.)

What is the expected loss per unit stake in Chuck-a-Luck? Only single-die bets are allowed.
#!/usr/bin/env ruby

TRIALS=50000

payout = 0

# First off, the game rules.  If we get one die right, 
# it pays out 1 times our stake.  If we get two dice,
# twice the stake, and three dice yields three times 
# the stake.  This function returns the multiplicand 
# of our stake; if we lose, it returns 0.
#
def win(bet)
	ret = 0

	d1 = 1+rand(6)
	d2 = 1+rand(6)
	d3 = 1+rand(6)

	ret += 1 if (d1 == bet)		
	ret += 1 if (d2 == bet)		
	ret += 1 if (d3 == bet)		

	ret +=1 if ret > 0 # we get our stake back, too

	return ret
end

# So, now, we play the game.  Since the dice are fair, 
# all numbers are equally likely, and we can bet on any
# number we choose each game.  To simplify things, 
# we'll always bet on 3.
TRIALS.times do
	payout += win(3) # we bet 1 unit on rolling a three
end

t = TRIALS # make the prints fit.

puts "After #{t} rounds of Chuck-a-Luck, we spent $#{t}"
puts "We got back $#{payout}.  Thus, our expected loss"
puts "  per unit stake is $#{(TRIALS-payout)/TRIALS.to_f}."

I've been coding my way through Fifty Challenging Problems in Statistics with Solutions. This post is a part of the Fifty Challenging Problems series.

This was brought to you by Josh Myer. He has other fun things at his homepage.