Skip to content

Instantly share code, notes, and snippets.

@rrguntaka
Created November 15, 2011 20:55
Show Gist options
  • Save rrguntaka/1368316 to your computer and use it in GitHub Desktop.
Save rrguntaka/1368316 to your computer and use it in GitHub Desktop.
Harmonic Mean
def har_mean(a)
a.size / a.map{|v| 1/v.to_f}.reduce(:+)
end
puts har_mean([6,9,12])
(defn har-mean [x]
(/ (count x) (reduce + (map #(/ 1 %1) x))))
(har-mean [6 9 12])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment