Created
October 24, 2020 15:00
-
-
Save nandanhere/bf9feb982deea3ffb9665934f44bbb66 to your computer and use it in GitHub Desktop.
Combinatronics formulae in swift #Combinatronics #Swift
This file contains hidden or 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
func factorial(_ number: Int) -> Int { | |
var fact = 1 | |
for n in 1..<number { | |
fact = fact + fact * n | |
} | |
return fact | |
} | |
func nCr(_ n: Int, _ r: Int) -> Int { | |
let nCr = factorial(n) / (r * factorial(n – r)) | |
return nCr | |
} | |
func nPr(_ n: Int, _ r: Int) -> Int { | |
let nPr = factorial(n) / factorial( n – r ) | |
return nPr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment