3 # $Id: matrix.ruby,v 1.2 2005-03-23 06:11:41 bfulgham Exp $
4 # http://shootout.alioth.debian.org/
6 # Contributed by Christopher Williams
8 n
= (ARGV[0] || 60).to_i
11 def mkmatrix(rows
, cols
)
13 Array
.new(rows
) do |i
|
14 Array
.new(cols
) {|j
| count
+=1 }
18 def mmult(rows
, cols
, m1
, m2
)
20 for i
in 0 .. (rows
- 1)
22 for j
in 0 .. (cols
- 1)
24 for k
in 0 .. (cols
- 1)
25 val
+= m1
[i
][k
] * m2
[k
][j
]
34 m1
= mkmatrix(size
, size
)
35 m2
= mkmatrix(size
, size
)
38 mm
= mmult(size
, size
, m1
, m2
)
40 puts
"#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"