Advertisement
wandrake

Untitled

Jun 4th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.30 KB | None | 0 0
  1. let hash = ref []
  2. let rec fibomem x =
  3.     if x < 0 then raise (Failure "fibomem") else
  4.     if x < 2
  5.         then 1
  6.         else (
  7.             try List.assoc x !hash with
  8.             Not_found ->
  9.                 let v = fibomem(x-1) + fibomem(x-2) in
  10.                 hash := (x, v) :: !hash; v
  11.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement