Created
February 24, 2010 16:06
-
-
Save lxmonk/313558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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