Created
July 9, 2012 19:00
-
-
Save anonymous/3078233 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
(defn better-sum-to [n] | |
(reduce + (range 1 (inc n)))) | |
(dotimes [_ 5] (time (better-sum-to 5000000))) ; reduce is 500 times slower | |
(println "") | |
(defn best-sum-to [n] | |
(/ (* n (inc n)) 2)) | |
(dotimes [_ 5] (time (best-sum-to 5000000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment