Skip to content

Commit edee698

Browse files
committed
updated syntax for Swift 3.1! 😁🔥
1 parent ab37359 commit edee698

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

Strassen Matrix Multiplication/StrassensMatrixMultiplication.playground/Contents.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//: Playground - noun: a place where people can play
2-
// Reference - http://mathworld.wolfram.com/StrassenFormulas.html
32

43
import Foundation
54

Strassen Matrix Multiplication/StrassensMatrixMultiplication.playground/Sources/Matrix.swift

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,44 @@
88

99
import Foundation
1010

11-
public enum RowOrColumn {
12-
case row, column
13-
}
14-
1511
public struct Matrix<T: Number> {
1612

13+
// MARK: - Martix Objects
14+
15+
public enum Index {
16+
case row, column
17+
}
18+
19+
public struct Size: Equatable {
20+
let rows: Int, columns: Int
21+
22+
public static func ==(lhs: Size, rhs: Size) -> Bool {
23+
return lhs.columns == rhs.columns && lhs.rows == rhs.rows
24+
}
25+
}
26+
1727
// MARK: - Variables
1828

1929
let rows: Int, columns: Int
30+
let size: Size
31+
2032
var grid: [T]
2133

2234
var isSquare: Bool {
2335
return rows == columns
2436
}
2537

26-
var size: MatrixSize {
27-
return MatrixSize(rows: rows, columns: columns)
28-
}
29-
3038
// MARK: - Init
3139

3240
public init(rows: Int, columns: Int, initialValue: T = T.zero) {
3341
self.rows = rows
3442
self.columns = columns
43+
self.size = Size(rows: rows, columns: columns)
3544
self.grid = Array(repeating: initialValue, count: rows * columns)
3645
}
3746

3847
public init(size: Int, initialValue: T = T.zero) {
39-
self.rows = size
40-
self.columns = size
41-
self.grid = Array(repeating: initialValue, count: rows * columns)
48+
self.init(rows: size, columns: size, initialValue: initialValue)
4249
}
4350

4451
// MARK: - Private Functions
@@ -59,7 +66,7 @@ public struct Matrix<T: Number> {
5966
}
6067
}
6168

62-
public subscript(type: RowOrColumn, value: Int) -> [T] {
69+
public subscript(type: Matrix.Index, value: Int) -> [T] {
6370
get {
6471
switch type {
6572
case .row:

Strassen Matrix Multiplication/StrassensMatrixMultiplication.playground/Sources/MatrixSize.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)