(* Exercice 1: 4pts *) (* 1-3 *) (* à tester soi-même *) (* 4 *) (* retourne la liste l dans laquelle les doublons ont été supprimés en commençant par la gauche *) (* 5 *) let mystere_rt l = let rec aux l ll = match l with [] -> ll | e :: tl -> aux tl (if List.mem e ll then ll else e :: ll) in aux (List.rev l) [] (* Exercice 2: 11pts *) (* 6 *) let rec remove_fst x l = match l with [] -> [] | e :: tl -> if e = x then remove_fst x tl else l (* 7 *) let rec remove_fst x l = match l with [] -> [] | e :: tl -> if e = x then remove_fst x tl else l (* 8 *) let suivant l = let rec aux l u = match l with [] -> u | x :: tl -> aux (remove_fst x l) (x :: count_fst x l :: u) in List.rev (aux l []) (* 9 *) let suite n = let rec aux n u = if n = 0 then u else aux (pred n) (suivant u) in aux n [1] (* 10 *) let suite_gen n first next = let rec aux n u = if n = 0 then u else aux (pred n) (next u) in aux n first (* 11 *) let notre_suite n = suite_gen n [1] suivant (* Exercice 3: 5pts *) (* 12 *) let make_tree root subtrees = T(root, subtrees) (* 13 *) let tree_subtrees tree = let T(_, subtrees) = tree in subtrees let tree_root tree = let T(root, _) = tree in root (* 14 *) let rec depth_first tree : int list = tree_root tree :: List.flatten (List.map depth_first (tree_subtrees tree))