#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Matrix_multiplication
#

func matrix_multi(a, b) {
    var m = [[]];
    a.range.each { |r|
        b.first.range.each { |c|
            b.range.each { |i|
                m[r][c] := 0 += (a[r][i] * b[i][c]);
            }
        }
    };
    return m;
};
 
var a = [
          [1, 2],
          [3, 4],
          [5, 6],
          [7, 8]
        ];
 
var b = [
          [1, 2, 3],
          [4, 5, 6]
        ];
 
matrix_multi(a, b).each {|line|
    say line.map{|i|'%3d'.sprintf(i)}.join(', ');
};
