#open "graphics" ;; open_graph "" ;; let rec est_valide = function | [] -> false | [0] -> true | [_] -> false | [_;_] -> false | g::h::d::_ when h<0 or g>=d -> false | [_;_;_] -> true | _::_::q -> est_valide q ;; let rec reduit l = match l with | [_] -> l | [_;_;_] -> l | g::h::d::k::u::q when h=k -> reduit (g::h::u::q) | g::h::q -> g::h::(reduit q) | _ -> failwith "liste incorrecte" ;; let p n = 10 * n ;; let dessine l = clear_graph() ; moveto 0 0 ; let rec aux x y = function | [g] -> lineto (p g) (p y) | g::h::q -> lineto (p g) (p y) ; lineto (p g) (p h) ; aux g h q | _ -> failwith "liste incorrecte" in aux 0 0 l ;; (* Q1 *) let rec cite_valide = function | [] -> true | (g,h,d)::q -> (g0) & (cite_valide q) ;; let ma_cite = [(20,20,50);(65,20,75);(10,40,30);(60,50,80)] ;; let immeuble_valide (g,h,d) = (g0) ;; let cite_valide = for_all immeuble_valide ;; (* Q2 *) let rec contour_valide = function | [g;h;d] -> g0 | g::h::d::q -> g=0 & contour_valide (d::q) | _ -> false ;; contour_valide [10;40;30;20;50;0;60;50;80] ;; (* Q3 *) let rec contour_reduit = function | [g;h;d] -> g0 | g::h::d::h'::q -> g=0 & h <> h' & contour_reduit (d::h'::q) | _ -> false ;; contour_reduit [10;40;30;20;50;0;60;50;80] ;; (* Q4 *) let dessine_contour l = clear_graph() ; let k = 10 in let rec aux x y = function | h::d::q -> lineto x h ; lineto d h ; aux d h q | [] -> lineto x 0 | _ -> failwith "liste incorrecte" in moveto (hd l) 0 ; aux (hd l) 0 (tl l) ;; dessine_contour [10;40;30;20;50;0;60;50;80] ;; (* Q5 *) let rec reduire_contour = function | g::h::d::h'::d'::q when h=h' -> reduire_contour (g::h::d'::q) | g::h::q -> g::h::(reduire_contour q) | [x] -> [x] | _ -> failwith "liste incorrecte" ;; reduire_contour [10;40;30;40;50;0;60;50;80] ;; (* Q6 *) let rec insere_immeuble (g,h,d) = function | [] -> [g;h;d] | g'::q when d g::h::d::0::g'::q | g'::q when d=g' -> g::h::g'::q | g'::h'::d'::q when g g::h::g'::(max h h')::d::h'::d'::q | g'::h'::d'::q when g g::h::g'::(max h h')::d'::q | g'::h'::d'::q when gd' -> let q' = insere_immeuble (d',h,d) (d'::q) in g::h::g'::(max h h')::q' | g'::h'::d'::q when g=g' & d g::(max h h')::d::h'::d'::q | g'::h'::d'::q when g=g' & d=d' -> g::(max h h')::d::q | g'::h'::d'::q when g=g' & d>d' -> let q' = insere_immeuble (d',h,d) (d'::q) in g::(max h h')::q' | g'::h'::d'::q when g' g'::h'::g::(max h h')::d::h'::d'::q | g'::h'::d'::q when g' g'::h'::g::(max h h')::d'::q | g'::h'::d'::q when g' let q' = insere_immeuble (d',h,d) (d'::q) in g'::h'::g::(max h h')::q' | g'::h'::d'::q when g' let q' = insere_immeuble (d',h,d) (d'::q) in g'::h'::q' | g'::h'::d'::q when g' let q' = insere_immeuble (g,h,d) (d'::q) in g'::h'::q' | [x] when x=g -> [g;h;d] | [x] when x [x;0;g;h;d] | _ -> failwith "liste incorrecte" ;; let rec contour_of_cite = function | [] -> [] | (g,h,d)::q -> insere_immeuble (g,h,d) (contour_of_cite q) ;; reduire_contour(contour_of_cite ma_cite) ;; (* Q7 *) let rec latex_of_contour = function (* let latex_of_cite l = latex_of_contour (contour_of_cite l) ;; *)