Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / bench / shootout / matrix.ruby
blobbf6808f47bd6fce91995a3f2139adebd590bc8b9
1 #!/usr/bin/ruby
2 # -*- mode: ruby -*-
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
9 size = 30
11 def mkmatrix(rows, cols)
12 count = 0
13 Array.new(rows) do |i|
14 Array.new(cols) {|j| count +=1 }
15 end
16 end
18 def mmult(rows, cols, m1, m2)
19 m3 = []
20 for i in 0 .. (rows - 1)
21 row = []
22 for j in 0 .. (cols - 1)
23 val = 0
24 for k in 0 .. (cols - 1)
25 val += m1[i][k] * m2[k][j]
26 end
27 row << val
28 end
29 m3 << row
30 end
32 end
34 m1 = mkmatrix(size, size)
35 m2 = mkmatrix(size, size)
36 mm = []
37 n.times do
38 mm = mmult(size, size, m1, m2)
39 end
40 puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"