Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
20
Task/Combinations/Swift/combinations.swift
Normal file
20
Task/Combinations/Swift/combinations.swift
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
func addCombo(prevCombo: [Int], var pivotList: [Int]) -> [([Int], [Int])] {
|
||||
|
||||
return (0..<pivotList.count)
|
||||
.map {
|
||||
_ -> ([Int], [Int]) in
|
||||
(prevCombo + [pivotList.removeAtIndex(0)], pivotList)
|
||||
}
|
||||
}
|
||||
func combosOfLength(n: Int, m: Int) -> [[Int]] {
|
||||
|
||||
return [Int](1...m)
|
||||
.reduce([([Int](), [Int](0..<n))]) {
|
||||
(accum, _) in
|
||||
accum.flatMap(addCombo)
|
||||
}.map {
|
||||
$0.0
|
||||
}
|
||||
}
|
||||
|
||||
println(combosOfLength(5, 3))
|
||||
Loading…
Add table
Add a link
Reference in a new issue