27 lines
806 B
Mojo
27 lines
806 B
Mojo
# probe: List[List[Int]] built row by row, multiplied and printed
|
|
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
|
# expect-stdout: [7, 10]
|
|
# expect-stdout: [15, 22]
|
|
def matmul(a: List[List[Int]], b: List[List[Int]]) -> List[List[Int]]:
|
|
var out = List[List[Int]]()
|
|
for i in range(len(a)):
|
|
var row = List[Int]()
|
|
for j in range(len(b[0])):
|
|
var s = 0
|
|
for k in range(len(b)):
|
|
s += a[i][k] * b[k][j]
|
|
row.append(s)
|
|
out.append(row^)
|
|
return out^
|
|
|
|
|
|
def main():
|
|
var a = List[List[Int]]()
|
|
var r1: List[Int] = [1, 2]
|
|
var r2: List[Int] = [3, 4]
|
|
a.append(r1^)
|
|
a.append(r2^)
|
|
var c = matmul(a, a)
|
|
for row in c:
|
|
print(row)
|