func permutations(_ n: Int, _ k: Int) -> Int {
var n = n
var answer = n
for _ in 1...k {
n -= 1
answer *= n
}
return answer
}
permutations(5, 3) //60 5P3
출처
Algorithms 라는 Library에서 Permutation 과 Combination을 지원해준다. (OCTOBER 7, 2020)
https://swift.org/blog/swift-algorithms/
https://github.com/apple/swift-algorithms/blob/main/Guides/Combinations.md