Last active
August 29, 2015 14:20
-
-
Save david-bergstrom/d0ede96a2e48d98cfe7a to your computer and use it in GitHub Desktop.
An algorithm for calculating the binomial coefficient written i Haskell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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