RosettaCodeData/Task/Dot-product/Erlang/dot-product.erl
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07:00

7 lines
257 B
Erlang

dotProduct(A,B) when length(A) == length(B) -> dotProduct(A,B,0);
dotProduct(_,_) -> erlang:error('Vectors must have the same length.').
dotProduct([H1|T1],[H2|T2],P) -> dotProduct(T1,T2,P+H1*H2);
dotProduct([],[],P) -> P.
dotProduct([1,3,-5],[4,-2,-1]).