Advertisement
Guest User

Memoized fibonacci

a guest
Apr 16th, 2011
242
0
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)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement