(********************************************************************)
(*  OCaml code from the book ``Learn Programming with OCaml''       *)
(*  See https://usr.lmf.cnrs.fr/lpo/                                *)
(*                                                                  *)
(*  Sylvain Conchon and Jean-Christophe Filliâtre                   *)
(*  Copyright 2025 Université Paris-Saclay and CNRS                 *)
(*                                                                  *)
(*  Openly licensed via CC BY SA 4.0                                *)
(*  See https://creativecommons.org/licenses/by-sa/4.0/deed.en      *)
(********************************************************************)

(* Program 85 on page 361
   Computing Fn via dynamic programming *)

let fib_dp n =
  if n = 0 then 0 else
  let f = Array.make (n+1) 0 in
  f.(1) <- 1;
  for i = 2 to n do f.(i) <- f.(i-2) + f.(i-1) done;
  f.(n)

This document was generated using caml2html