mp2i-info/dm4/bin/main.ml
2025-11-08 20:43:00 +01:00

28 lines
630 B
OCaml

(* let plusetfois a b = (a+b, a*b);;
(* assert (plusetfois 5 6 == (11, 30));; *)
let rec pp2_h n = match n with
| 0 -> 1
| _ -> 2 * (pp2_h (n/2))
;;
let pp2 n = if n == 0 then 0 else pp2_h (n-1);;
(* assert (pp2 10 == 16);;
assert (pp2 32 == 32);;
assert (pp2 1 == 1);;
assert (pp2 0 == 0);; *)
let leeloo l = match l with
| _::_::_::_::a::_ -> a
| _ -> failwith "Not enough elements";;
(* assert (leeloo [2; 65; 2; 3; 7; 2] == 7);; *)
let rec coupe l = match l with
| a::b::q ->
let qa, qb = coupe q in
a::qa, b::qb
| _ -> l, []
;;
(* assert (coupe [2; 65; 4; 3; 7; 2] == ([2; 4; 7], [65; 3; 2])); *) *)