SHARE
TWEET

Memoized fibonacci

a guest Apr 16th, 2011 193 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (def memo-fib
  2.   (memoize
  3.     #(if (< % 2)
  4.        1
  5.        (+ (memo-fib (dec %)) (memo-fib (- % 2))))))
  6.      
  7. ; "dynamic programming step" (necessary to avoid stack overflow)
  8. (doseq [i (range 1 1000)] (memo-fib i))
  9.  
  10. (time (println (memo-fib 1000)))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top