mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-05 20:26:53 +08:00
88c45cccac
- `func` keyword has change to `function`. - `elsif` changed to `else if`
33 lines
493 B
Plaintext
33 lines
493 B
Plaintext
|
|
## Multiply two matrices.
|
|
|
|
## A is 3x3 matrix
|
|
A = [[1, 2, 3],
|
|
[4, 5, 6],
|
|
[7, 8, 9]]
|
|
|
|
## B is 3x4 matrix.
|
|
B = [[4, 6, 3, 2],
|
|
[8, 7, 0, 2],
|
|
[6, 0, 9, 4]]
|
|
|
|
## Result is 3x4 matrix.
|
|
R = [[0,0,0,0],
|
|
[0,0,0,0],
|
|
[0,0,0,0]]
|
|
|
|
## Iterate through rows of A.
|
|
for i in 0..(A.length)
|
|
## Iterate through columns of B.
|
|
for j in 0..(B[0].length)
|
|
for k in 0..(B.length)
|
|
R[i][j] += A[i][k] * B[k][j]
|
|
end
|
|
end
|
|
end
|
|
|
|
for row in R
|
|
print(row)
|
|
end
|
|
|