Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created August 15, 2013 18:48
Show Gist options
  • Select an option

  • Save aamedina/6243580 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6243580 to your computer and use it in GitHub Desktop.
;; sometimes it's useful to cache results of previous computations so you don't have to repeat them again
(def sum (memo #(reduce + (range %)))
;; where the input to sum is the limit of the range of the numbers you want to sum
(time (sum 100000))
"Elapsed time: 44.191 msecs"
4999950000
;; again?
(time (sum 100000))
"Elapsed time: 0.417 msecs"
4999950000
;; kthx computer science
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment