Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2012 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3078233 to your computer and use it in GitHub Desktop.
Save anonymous/3078233 to your computer and use it in GitHub Desktop.
(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