Informatique/MPSI/spe/cours/cous 2.ml

17 lines
278 B
OCaml
Raw Permalink Normal View History

2020-01-28 10:10:46 +01:00
let catalan n =
let t = Array.make (n+1) 0 in
t.(0) <- 1;
for i=1 to n do
for k=0 to i-1 do
t.(i) <- (t.(k)*t.(i-1-k)) + t.(i)
done
done;
t.(n);;
catalan 5;;
let rec est_triee l = match l with
| [] -> true
| [a] -> true
| a::(b::t) -> a<=b && est_triee b::t;;