Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 23rd, 2012  |  syntax: Haskell  |  size: 0.36 KB  |  views: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. memoized_fib :: Int -> Integer
  2. memoized_fib = (map fib [0..] !!)
  3.         where fib 0 = 0
  4.               fib 1 = 1
  5.               fib n = memoized_fib(n - 2) + memoized_fib(n - 1)
  6.  
  7. memoized_fib2 :: Int -> Integer
  8. memoized_fib2 n = (map fib[0..]) !! n
  9.         where fib 0 = 0
  10.               fib 1 = 1
  11.               fib n = memoized_fib2(n - 2) + memoized_fib2(n - 1)