Skip to content

Instantly share code, notes, and snippets.

@david-bergstrom
Last active August 29, 2015 14:20
Show Gist options
  • Save david-bergstrom/d0ede96a2e48d98cfe7a to your computer and use it in GitHub Desktop.
Save david-bergstrom/d0ede96a2e48d98cfe7a to your computer and use it in GitHub Desktop.
An algorithm for calculating the binomial coefficient written i Haskell.
choose n 1 = n
choose n k
| k > n = -1
| k > n - k = choose n (n - k)
| otherwise = ((choose n (k - 1)) * (n - k + 1)) `div` k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment