Skip to content

Instantly share code, notes, and snippets.

@isaacsu
Created May 14, 2012 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacsu/2697844 to your computer and use it in GitHub Desktop.
Save isaacsu/2697844 to your computer and use it in GitHub Desktop.
sim-distance in clojure
(defn sim-distance [critic1 critic2]
; work out movies that both critics have rated
(let [shared-movies
((fn [c1 c2]
(map #(first %) (filter #(c2 (first %)) c1))) critic1 critic2)]
; return 0 if they have no ratings in common
(if (= (count shared-movies) 0)
0
; compute distance
(/ 1 (+ 1 (reduce + (map #(expt (- (critic1 %) (critic2 %)) 2) shared-movies)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment