Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Dot-product/Clojure/dot-product.clj
Normal file
20
Task/Dot-product/Clojure/dot-product.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(defn dot-product [& matrix]
|
||||
{:pre [(apply == (map count matrix))]}
|
||||
(apply + (apply map * matrix)))
|
||||
|
||||
(defn dot-product2 [x y]
|
||||
(->> (interleave x y)
|
||||
(partition 2 2)
|
||||
(map #(apply * %))
|
||||
(reduce +)))
|
||||
|
||||
(defn dot-product3
|
||||
"Dot product of vectors. Tested on version 1.8.0."
|
||||
[v1 v2]
|
||||
{:pre [(= (count v1) (count v2))]}
|
||||
(reduce + (map * v1 v2)))
|
||||
|
||||
;Example Usage
|
||||
(println (dot-product [1 3 -5] [4 -2 -1]))
|
||||
(println (dot-product2 [1 3 -5] [4 -2 -1]))
|
||||
(println (dot-product3 [1 3 -5] [4 -2 -1]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue