```
def multiply(a, b)
ar = a.length
ac = a[0].length
bc = b[0].length
result = Array.new(ar, 0){Array.new(bc, 0)}
ar.times do |i|
(0...ac).each do |n|
next if a[i][n] == 0
bc.times do |j|
next if b[n][j] == 0
result[i][j] += a[i][n] * b[n][j]
end
end
end
result
end
```