Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let hash = ref []
- let rec fibomem x =
- if x < 0 then raise (Failure "fibomem") else
- if x < 2
- then 1
- else (
- try List.assoc x !hash with
- Not_found ->
- let v = fibomem(x-1) + fibomem(x-2) in
- hash := (x, v) :: !hash; v
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement