Skip to content

Instantly share code, notes, and snippets.

@Quantisan
Created August 6, 2011 18:08
Show Gist options
  • Save Quantisan/1129582 to your computer and use it in GitHub Desktop.
Save Quantisan/1129582 to your computer and use it in GitHub Desktop.
Calculating euclidean distance using tree composition
(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