Created
August 6, 2011 18:08
-
-
Save Quantisan/1129582 to your computer and use it in GitHub Desktop.
Calculating euclidean distance using tree composition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def x [1 2]) | |
(def y [4 5]) | |
(defn- tree-comp-each [root branch & leaves] | |
(apply | |
root (map branch leaves))) | |
(defn euclidean-distance | |
[a b] | |
{:pre [(= (count a) (count b))]} | |
(sqrt | |
(apply | |
tree-comp-each | |
+ | |
(fn [[x y]] | |
(pow (- x y) 2)) | |
(map vector a b)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment