3 # $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $
4 # http://www.bagley.org/~doug/shootout/
6 n = 60 #Integer(ARGV.shift || 1)
10 def mkmatrix(rows, cols)
13 (0 .. (rows - 1)).each do |bi|
14 row = Array.new(cols, 0)
15 (0 .. (cols - 1)).each do |j|
24 def mmult(rows, cols, m1, m2)
26 (0 .. (rows - 1)).each do |bi|
27 row = Array.new(cols, 0)
28 (0 .. (cols - 1)).each do |j|
30 (0 .. (cols - 1)).each do |k|
31 val += m1.at(bi).at(k) * m2.at(k).at(j)
40 m1 = mkmatrix(size, size)
41 m2 = mkmatrix(size, size)
44 mm = mmult(size, size, m1, m2)
46 # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"