Skip to content

Instantly share code, notes, and snippets.

@BasThomas
Created April 1, 2019 09:57
Show Gist options
  • Save BasThomas/559f453d16c07f679e1022110a6fc608 to your computer and use it in GitHub Desktop.
Save BasThomas/559f453d16c07f679e1022110a6fc608 to your computer and use it in GitHub Desktop.
struct Vector<T> {
let size: Int
let initialValue: T
struct Position: Equatable {
let row: Int
let column: Int
}
typealias Matrix = [Position]
let matrix: Matrix
init(size: Int, initialValue: T) {
self.size = size
self.initialValue = initialValue
var _matrix: Matrix = []
for row in 0..<size {
for column in 0..<size {
_matrix.append(.init(row: row, column: column))
}
}
self.matrix = _matrix
}
}
extension Vector: Equatable where T: Equatable {}
@BasThomas
Copy link
Author

let threeVector = Vector<Int>.init(size: 3, initialValue: 0)
threeVector.matrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment