Actuarial Programming

Python Haskell R and so on

Monty Carlo Simulation in Haskell

with 4 comments

montycarlo_hs1

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

Written by n0ne

January 5, 2009 at 4:03 pm

Posted in Haskell

4 Responses

Subscribe to comments with RSS.

  1. 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

  2. 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 Ewton

    January 5, 2009 at 4:21 pm

  3. […] 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 […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: