Previous Up Next
Version pdf - Version archive

4.2  Listes

fichier source

(* exercice 1 *) let rec n_a_un = function 0 -> [] | n -> n::(n_a_un (n - 1));; (* exercice 2 *) let rec un_a_n_acc n acc = if (n = 0) then acc else un_a_n_acc (n-1) (n::acc);; let un_a_n n = un_a_n_acc n [];; (* exercice 3 *) let rec supprime l n = if (n <= 0) then l else match l with [] -> [] | head::tail -> supprime tail (n-1);; (* exercice 4 *) let rec long_prefixe l = match l with [] -> 0 | x::[] -> 1 | x::y::tail -> if (x = y) then 1 + long_prefixe (y::tail) else 1;;

Previous Up Next