Skip to content

Commit e5624e8

Browse files
Wesley-Arringtonjiegillet
authored andcommitted
Adjusting Whitespace in Swift Code (#288)
1 parent c9c7483 commit e5624e8

File tree

7 files changed

+8
-26
lines changed

7 files changed

+8
-26
lines changed

contents/bogo_sort/bogo_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In code, it looks something like this:
3636
{% sample lang="rs" %}
3737
[import:16-20, lang:"rust"](code/rust/bogosort.rs)
3838
{% sample lang="swift" %}
39-
[import:32-39, lang:"swift"](code/swift/bogosort.swift)
39+
[import:25-31, lang:"swift"](code/swift/bogosort.swift)
4040
{% endmethod %}
4141

4242
That's it.

contents/bogo_sort/code/swift/bogosort.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
import Foundation
22

3-
43
func isSorted(inputArray: [Int]) -> Bool {
5-
64
for i in 0..<inputArray.count-1 {
75
if inputArray[i] > inputArray[i+1] {
86
return false
97
}
108
}
11-
9+
1210
return true
1311
}
1412

15-
16-
1713
func shuffle(inputArray: inout [Int]) -> [Int] {
18-
1914
var shuffledArray = [Int]()
2015

2116
for _ in 0..<inputArray.count {
2217
let rand = Int(arc4random_uniform(UInt32(inputArray.count)))
2318
shuffledArray.append(inputArray[rand])
2419
inputArray.remove(at: rand)
2520
}
26-
21+
2722
return shuffledArray
2823
}
2924

30-
31-
3225
func bogoSort(sortArray: inout [Int]) -> [Int] {
33-
3426
while(!isSorted(inputArray: sortArray)) {
3527
sortArray = shuffle(inputArray: &sortArray)
3628
}
37-
29+
3830
return sortArray
3931
}
4032

contents/bubble_sort/bubble_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
3535
{% sample lang="racket" %}
3636
[import:6-19, lang:"racket"](code/racket/bubbleSort.rkt)
3737
{% sample lang="swift" %}
38-
[import:1-12, lang:"swift"](code/swift/bubblesort.swift)
38+
[import:1-13, lang:"swift"](code/swift/bubblesort.swift)
3939
{% sample lang="ti83b" %}
4040
[import:2-13, lang:"ti-83_basic"](code/ti83basic/BUBLSORT.txt)
4141
{% endmethod %}

contents/bubble_sort/code/swift/bubblesort.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
func bubbleSort(sortArray: inout [Int]) -> [Int] {
2-
32
for i in (1..<sortArray.count).reversed() {
43
for j in 0..<i {
54
if sortArray[j] > sortArray[j+1] {

contents/forward_euler_method/code/swift/euler.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ func solveEuler(timeStep: Double, n: Int) -> [Double] {
66
for i in 1...n {
77
result.append(result[i - 1] - 3 * result[i - 1] * timeStep)
88
}
9+
910
return result
1011
}
1112

@@ -19,6 +20,7 @@ func checkResult(result: [Double], threshold: Double, timeStep: Double) -> Bool
1920
isApprox = false
2021
}
2122
}
23+
2224
return isApprox
2325
}
2426

contents/monte_carlo_integration/code/swift/monte_carlo.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,21 @@
22

33
import Foundation
44

5-
6-
75
public extension Double {
8-
96
public static var random: Double {
10-
117
return Double(arc4random()) / 0xFFFFFFFF // Returns a random double between 0.0 and 1.0, inclusive.
128
}
139

1410
public static func random(min: Double, max: Double) -> Double {
15-
1611
return Double.random * (max - min) + min
1712
}
1813
}
1914

20-
2115
func isInCircle(x: Double, y: Double, radius: Double) -> Bool {
22-
2316
return (x*x) + (y*y) < radius*radius
2417
}
2518

26-
2719
func monteCarlo(n: Int) -> Double {
28-
2920
let radius: Double = 1
3021
var piCount = 0
3122
var randX: Double
@@ -41,11 +32,9 @@ func monteCarlo(n: Int) -> Double {
4132
}
4233

4334
let piEstimate = Double(4 * piCount)/(Double(n))
44-
4535
return piEstimate
4636
}
4737

48-
4938
func main() {
5039
let piEstimate = monteCarlo(n: 10000)
5140
print("Pi estimate is: ", piEstimate)

contents/monte_carlo_integration/monte_carlo_integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ each point is tested to see whether it's in the circle or not:
5858
{% sample lang="java" %}
5959
[import:13-15, lang:"java"](code/java/MonteCarlo.java)
6060
{% sample lang="swift" %}
61-
[import:21-25, lang:"swift"](code/swift/monte_carlo.swift)
61+
[import:15-17 lang:"swift"](code/swift/monte_carlo.swift)
6262
{% endmethod %}
6363

6464
If it's in the circle, we increase an internal count by one, and in the end,

0 commit comments

Comments
 (0)