Rash thoughts about .NET, C#, F# and Dynamics NAV.

"Every solution will only lead to new problems."

Wednesday, 17. August 2011

Some special monads in F# – Part 5 of n – Application: Poker – Your chance to get rich!

Filed under: F#,Informatik — Steffen Forkmann at 8:52 Uhr

In the last part of this blog series I showed how we can utilize the DistributionMonad in order to solve the famous Monty Hall problem. This time I want to show you how we can use it to solve some basic Texas hold’em poker questions.

We start by defining a model for poker in F#:

As you can see we model cards as tuples of a rank and a suit. The complete deck is just a combination of all ranks with all suits.

Now we need some additional helpers for the DistributionMonad, which will allow us to draw cards from the deck. You can find further explanations about these helpers in the excellent paper by Martin Erwig and Steve Kollmansberger called "Functional Pearls: Probabilistic functional programming in Haskell". Like the DistributionMonad itself, these helpers are already in the FSharp.Monad project and you get the bits from nuget.org.

Now we are ready to perform our first query. Let’s see how we can compute the probability of drawing the Ace of Clubs and the Ace of Spades:

But we can easily go a step further:

If you keep this model in mind you might come up with a poker odds calculator on a smart phone. This might be your chance to get rich. 😉

Tags: ,


  1. […] Some special monads in F# – Part 5 of n – Application: Poker (Steffen Forkmann) […]

    Pingback by Dew Drop – August 17, 2011 | Alvin Ashcraft's Morning Dew — Wednesday, 17. August 2011 um 12:01 Uhr

  2. lol.. step by step on how to get riched 🙂
    amazing snippt of codes.

    Comment by طراحی سایت — Friday, 7. October 2011 um 15:12 Uhr

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> .