Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,50 @@
@inlinable
public func matrixTranspose<T>(_ matrix: [[T]]) -> [[T]] {
guard !matrix.isEmpty else {
return []
}
var ret = Array(repeating: [T](), count: matrix[0].count)
for row in matrix {
for j in 0..<row.count {
ret[j].append(row[j])
}
}
return ret
}
@inlinable
public func printMatrix<T>(_ matrix: [[T]]) {
guard !matrix.isEmpty else {
print()
return
}
let rows = matrix.count
let cols = matrix[0].count
for i in 0..<rows {
for j in 0..<cols {
print(matrix[i][j], terminator: " ")
}
print()
}
}
let m1 = [
[1, 2, 3],
[4, 5, 6]
]
print("Input:")
printMatrix(m1)
let m2 = matrixTranspose(m1)
print("Output:")
printMatrix(m2)