Today a colleague and I were working with some games that required Combination formulas to calculate the returns (or yields) for the gambler and the house. Like if I play the roulette, which are my odds of winning? Most of the probabilities are calculated based on counting favorable samples such as if I bet 1 number out of 35.

In other cases, like Keno, you need to calculate the winning odds using a formula which requires combinations. Unfortunately in ruby we don't have out-of-the-box probability helpers, so Foca showed us a nice trick to add such a method with lambdas in ruby:

factorial = ->(n) { n <= 1 ? 1 : n * factorial[n-1] }
combination = ->(n,k) { factorial[n]/factorial[k]/factorial[n-k] }
combination[52,5]
 => 2598960

Of couse we could do an iterative solution for it, but it is quite handy for simple calculations.