Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created June 22, 2014 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfix/02ca4d9537af011dd12f to your computer and use it in GitHub Desktop.
Save rayfix/02ca4d9537af011dd12f to your computer and use it in GitHub Desktop.
Compute Probability of Ace of Diamonds in a Poker Hand
func testPokerAceOfDiamonds()
{
let handsWithAceOfDiamonds = Binomial(n: 51, choose: 4)
let allPossibleHands = Binomial(n: 52, choose: 5)
let probabilityOfAceOfDiamonds = handsWithAceOfDiamonds / allPossibleHands
XCTAssertEqual(probabilityOfAceOfDiamonds, Rational(5,52))
let probabilityOfNoAceOfDiamonds = Rational(1) - probabilityOfAceOfDiamonds
XCTAssertEqual(probabilityOfNoAceOfDiamonds, Rational(47,52))
}
@rayfix
Copy link
Author

rayfix commented Jun 22, 2014

This example uses my simple RAFIntMath framework. https://github.com/rayfix/RAFIntMath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment