Skip to content

Commit 403e11c

Browse files
committed
Updated files for 2 spaced-indentations
1 parent 7ce3763 commit 403e11c

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

Shuffle/Shuffle.playground/Sources/Shuffle.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import Foundation
22

33
/* Returns a random integer between 0 and n-1. */
44
public func random(_ n: Int) -> Int {
5-
return Int(arc4random_uniform(UInt32(n)))
5+
return Int(arc4random_uniform(UInt32(n)))
66
}
77

88
extension Array {
99
/*
10-
Randomly shuffles the array in-place
11-
This is the Fisher-Yates algorithm, also known as the Knuth shuffle.
12-
Time complexity: O(n)
13-
*/
10+
Randomly shuffles the array in-place
11+
This is the Fisher-Yates algorithm, also known as the Knuth shuffle.
12+
Time complexity: O(n)
13+
*/
1414
public mutating func shuffle() {
1515
for i in (1...count-1).reversed() {
1616
let j = random(i + 1)
@@ -24,8 +24,8 @@ extension Array {
2424
}
2525

2626
/*
27-
Simultaneously initializes an array with the values 0...n-1 and shuffles it.
28-
*/
27+
Simultaneously initializes an array with the values 0...n-1 and shuffles it.
28+
*/
2929
public func shuffledArray(_ n: Int) -> [Int] {
3030
var a = Array(repeating: 0, count: n)
3131
for i in 0..<n {

Shuffle/Shuffle.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@ import Foundation
22

33
/* Returns a random integer between 0 and n-1. */
44
public func random(_ n: Int) -> Int {
5-
return Int(arc4random_uniform(UInt32(n)))
5+
return Int(arc4random_uniform(UInt32(n)))
66
}
77

88
extension Array {
9-
/*
10-
Randomly shuffles the array in-place
11-
This is the Fisher-Yates algorithm, also known as the Knuth shuffle.
12-
Time complexity: O(n)
13-
*/
14-
public mutating func shuffle() {
15-
for i in (1...count-1).reversed() {
16-
let j = random(i + 1)
17-
if i != j {
18-
let t = self[i]
19-
self[i] = self[j]
20-
self[j] = t
21-
}
22-
}
9+
/*
10+
Randomly shuffles the array in-place
11+
This is the Fisher-Yates algorithm, also known as the Knuth shuffle.
12+
Time complexity: O(n)
13+
*/
14+
public mutating func shuffle() {
15+
for i in (1...count-1).reversed() {
16+
let j = random(i + 1)
17+
if i != j {
18+
let t = self[i]
19+
self[i] = self[j]
20+
self[j] = t
21+
}
2322
}
23+
}
2424
}
2525

2626
/*
2727
Simultaneously initializes an array with the values 0...n-1 and shuffles it.
2828
*/
2929
public func shuffledArray(_ n: Int) -> [Int] {
30-
var a = Array(repeating: 0, count: n)
31-
for i in 0..<n {
32-
let j = random(i + 1)
33-
if i != j {
34-
a[i] = a[j]
35-
}
36-
a[j] = i // insert next number from the sequence
30+
var a = Array(repeating: 0, count: n)
31+
for i in 0..<n {
32+
let j = random(i + 1)
33+
if i != j {
34+
a[i] = a[j]
3735
}
38-
return a
36+
a[j] = i // insert next number from the sequence
37+
}
38+
return a
3939
}
4040

0 commit comments

Comments
 (0)