Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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)
; 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
You can’t perform that action at this time.