Skip to content

Commit 3d01e14

Browse files
authored
Merge pull request kodecocodes#709 from minuscorp/patch-1
Update Combinatorics to match Swift 4 API
2 parents 40d3471 + 6bf3a16 commit 3d01e14

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Combinatorics/README.markdown

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ Here's a recursive algorithm by Niklaus Wirth:
9999

100100
```swift
101101
func permuteWirth<T>(_ a: [T], _ n: Int) {
102-
if n == 0 {
103-
print(a) // display the current permutation
104-
} else {
105-
var a = a
106-
permuteWirth(a, n - 1)
107-
for i in 0..<n {
108-
swap(&a[i], &a[n])
109-
permuteWirth(a, n - 1)
110-
swap(&a[i], &a[n])
102+
if n == 0 {
103+
print(a) // display the current permutation
104+
} else {
105+
var a = a
106+
permuteWirth(a, n - 1)
107+
for i in 0..<n {
108+
a.swapAt(i, n)
109+
permuteWirth(a, n - 1)
110+
a.swapAt(i, n)
111+
}
111112
}
112-
}
113113
}
114114
```
115115

0 commit comments

Comments
 (0)