Skip to content

Instantly share code, notes, and snippets.

@kballenegger
Created May 29, 2012 06:54
Show Gist options
  • Save kballenegger/f15484c5c3aaa7e69276 to your computer and use it in GitHub Desktop.
Save kballenegger/f15484c5c3aaa7e69276 to your computer and use it in GitHub Desktop.
def sim(first, second)
shared = $critics[first].keys.inject([]) {|a,k| a << k if $critics[second][k] }
return 0 if shared.empty?
sum = shared.map{|e| ($critics[first][e] - $critics[second][e]) ** 2 }.reduce(&:+)
1/(1+Math.sqrt(sum))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment