(* Exercice 1 *) (* 1. 2. 3. 4. 5. 6. *) (* À tester vous-même *) (* Exercice 2 *) (* 7. *) fun x y -> x +. float_of_int y (* 8. *) fun x y -> x + y, x = y (* 9. *) fun f g x -> f x = g x (* 10. *) fun f g -> fun x -> f (succ (g x)) (* Exercice 3 *) (* 11 *) let iota n = let rec aux n l = if n = -1 then l else aux (pred n) (n :: l) in aux (n - 1) [] (* Exercice 4 *) (* 12 *) let cartesian x y = let rec aux a b couples = if a = -1 then couples else if b = -1 then aux (pred a) y couples else aux a (pred b) ((a,b) :: couples) in aux x y [] (* Exercice 5 *) (* 13 *) let make_point x y = Point(x, y) (* 14 *) let p_x point = let Point(x, _) = point in x let p_y point = let Point(_, y) = point in y (* 15 *) let distance_manhattan point1 point2 = abs(p_x point1 - p_x point2) + abs(p_y point1 - p_y point2) (* Exercice 5 *) (* 16 *) let pset_full : pset = fun point -> true (* 17 *) let pset_make_singleton point : pset = fun (p : point) -> point = p (* 18 *) let pset_complement pset = fun point -> not (pset_member point pset) (* 19 *) let pset_union pset1 pset2 : pset = fun point -> pset_member point pset1 || pset_member point pset2 (* 20 *) let odd_p n = n mod 2 = 1 let pset_odd = fun point -> odd_p (p_x point) && odd_p (p_y point) (* 21 *) let pset_of_points points : pset = fun point -> List.mem point points (* 22 *) let all_points x y = List.map (fun couple -> make_point (fst couple) (snd couple)) (cartesian x y) (* 23 *) let pset_find_px pset a = let rec aux x = if x > a then None else let p = make_point x 0 in if pset_member p pset then Some p else aux (succ x) in aux 0