## Monty Carlo Simulation in Haskell

Just created a simple simulation of the Monty Carlo game using Haskell. Apparently the code above did not fully utilize the powerful syntax of Haskell, but it is my first product. Most importantly, it gives me the right conclusion the probability of winning by staying/switching is 33.3%/66.7%. So remember, always choose to switch!

At first it was tricky to get the types correct. And it was tricky about the indentation too. After all, it was fun and I have learnt something that I already knew in a practical way. I will feed in the details tomorrow night, if I have time ^_^.

Advertisements

Does anyone know how to post code in wordpress here? I think a screenshot is a rather dumb idea.

金樽月January 5, 2009 at 4:05 pm

If you have 3 choices (a,b,c), and you choose ‘a’.

If you are shown that ‘b’ is wrong and offered the choice of staying with ‘a’ or switching to ‘c’, the odds favor the switch. Here’s why:

When you pick ‘a’ from a,b,c… you have a 1/3 chance of being correct. After you are shown that ‘b’ is the wrong choice (and ‘b’ is then removed) if you stay with your initial choice your odds remain at 1/3.

However, if you switch to ‘c’, you know have a 1/2 chance of being correct. It seems screwy, but ask any stats major… they will confirm.

I only wrote this comment b/c your post said 1/3 to stay and 2/3 to switch. It’s actually 1/3 to stay, 1/2 to switch.

Jason EwtonJanuary 5, 2009 at 4:21 pm

well, I was actually more interested in the programming part..:) anyway, I must be wrong about the odds, but the short code was inspired by this blog

Monte Carlo Simulation of the Monty Hall Problems in Ruby and Python

which forwards me to this wiki

wiki, which in turn makes believe it’s 1/3 and 2/3. we may be referring to different objects. But thanks for writing here.

金樽月January 6, 2009 at 2:42 am

[…] Hall problem using Monte Carlo simulations Jump to Comments n0ne showed how to translate Monte Carlo simulations of the Monty Hall Problem from Ruby and Python to […]

Monty Hall problem using Monte Carlo simulations « Random DeterminismJanuary 7, 2009 at 3:30 am