Skip to content

Instantly share code, notes, and snippets.

@tylerdiaz
Created August 14, 2014 19:29
Show Gist options
  • Save tylerdiaz/150e2074d308653566d2 to your computer and use it in GitHub Desktop.
Save tylerdiaz/150e2074d308653566d2 to your computer and use it in GitHub Desktop.
E. Distance algo
(defn square [x]
(* x x))
(defn euclidean-distance [p q]
(Math/sqrt (->> (map - q p) (map square) (reduce +))))
; This formula calculates the distance, which will be smaller for people who are more similar.
; However, you need a function that gives higher values for people who are similar.
; This can be done by adding 1 to the function (so you don’t get a division-by- zero error) and inverting it:
(/ 1 (euclidean-distance([0 1 5 4 5 3 1] [0 0 3 4 5 4 5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment