Skip to content

Instantly share code, notes, and snippets.

@anyley
Last active October 15, 2017 13:24
Show Gist options
  • Save anyley/0de0662eea378a2eb57a24d103516b93 to your computer and use it in GitHub Desktop.
Save anyley/0de0662eea378a2eb57a24d103516b93 to your computer and use it in GitHub Desktop.
def matrix_mult(a, b)
a.map do |ar|
ar.each_index.map do |aci|
b.each_with_index.reduce(0) do |sum, (br, bri)|
sum + ar[bri] * br[aci]
end
end
end
end
def m_mult(a, b)
a.map { |ar| ar.each_index.map { |aci| b.each_with_index.reduce(0) { |sum, (br, bri)| sum + ar[bri] * br[aci] }}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment