Skip to content

Instantly share code, notes, and snippets.

@lxmonk
Created February 24, 2010 16:06
Show Gist options
  • Save lxmonk/313558 to your computer and use it in GitHub Desktop.
Save lxmonk/313558 to your computer and use it in GitHub Desktop.
;; http://rosettacode.org/wiki/Averages/Pythagorean_means
;; according to the python solution.
(use '[clojure.contrib.math :only (expt)])
(defn a-mean [coll]
(/ (reduce + coll) (count coll)))
(defn g-mean [coll]
(expt (reduce * coll) (/ (count coll))))
(defn h-mean [coll] ;; Michael Kohl's function
(/ (count coll) (reduce + (map / coll))))
(let [numbers (range 1 11)
a (a-mean numbers) g (g-mean numbers) h (h-mean numbers)]
(println a ">=" g ">=" h)
(>= a g h))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment