Dot product: Difference between revisions

Content added Content deleted
(→‎{{header|Raku}}: create a subroutine)
(→‎{{header|Ruby}}: use sum method)
Line 2,876: Line 2,876:
def dot_product(other)
def dot_product(other)
raise "not the same size!" if self.length != other.length
raise "not the same size!" if self.length != other.length
self.zip(other).inject(0) {|dp, (a, b)| dp += a*b}
zip(other).sum {|a, b| a*b}
end
end
end
end