From d6ed37ab47de58afb9ab61f56eee3ca9017a33e5 Mon Sep 17 00:00:00 2001 From: Mythrann Date: Thu, 4 Feb 2021 20:11:33 +0100 Subject: [PATCH] lol --- .../exos-preparatoires/mission1.html | 209 ++++++++---------- .../exos-preparatoires/mission2.html | 158 +++++-------- .../exos-preparatoires/solution-en-ocaml.html | 119 +++++----- 3 files changed, 203 insertions(+), 283 deletions(-) diff --git a/Y/Ada-S2/Programmes/exos-preparatoires/mission1.html b/Y/Ada-S2/Programmes/exos-preparatoires/mission1.html index fac6a62..f2003b1 100644 --- a/Y/Ada-S2/Programmes/exos-preparatoires/mission1.html +++ b/Y/Ada-S2/Programmes/exos-preparatoires/mission1.html @@ -1,154 +1,131 @@ - + + +mission1.adb
with Gada.Text_IO ; - - mission1.adb - - - - +procedure Mission1 is - - -
with Gada.Text_IO ; + package Txt renames GAda.Text_IO ; - procedure Mission1 is - - package Txt renames GAda.Text_IO ; - - procedure Tracer_Ligne (Long : Integer) is - begin + procedure Tracer_Ligne (Long : Integer) is + begin -- Tracer n fois le caractère # puis passer à la ligne. - for Colonne in 1..Long loop - Txt.Put("#") ; + for Colonne in 1..Long loop + Txt.Put("#") ; end loop ; Txt.New_Line ; - end Tracer_Ligne ; + end Tracer_Ligne ; - procedure Tracer_Rectangle (Largeur : Integer ; Hauteur : Integer) is - begin + procedure Tracer_Rectangle (Largeur : Integer ; Hauteur : Integer) is + begin -- Première ligne, pleine - Tracer_Ligne(Largeur) ; + Tracer_Ligne(Largeur) ; - -- Les lignes suivantes (de 2 à Hauteur-1) ne contiennent que - -- le caractère # du début et celui de la fin. - for Ligne in 2..Hauteur - 1 loop - Txt.Put("#") ; + -- Les lignes suivantes (de 2 à Hauteur-1) ne contiennent que + -- le caractère # du début et celui de la fin. + for Ligne in 2..Hauteur - 1 loop + Txt.Put("#") ; - -- Des espaces au milieu. - for Col in 2..Largeur - 1 loop - Txt.Put(" ") ; + -- Des espaces au milieu. + for Col in 2..Largeur - 1 loop + Txt.Put(" ") ; + end loop ; + + Txt.Put("#") ; + Txt.New_Line ; end loop ; - Txt.Put("#") ; + -- La dernière ligne est pleine. + Tracer_Ligne(Largeur) ; Txt.New_Line ; - end loop ; + end Tracer_Rectangle ; - -- La dernière ligne est pleine. - Tracer_Ligne(Largeur) ; - Txt.New_Line ; - end Tracer_Rectangle ; - - procedure Tracer_Quadrillage (Largeur : Integer ; Hauteur : Integer) is - begin + procedure Tracer_Quadrillage (Largeur : Integer ; Hauteur : Integer) is + begin -- On dessine ligne par ligne, colonne par colonne. - for Ligne in 1..Hauteur loop - for Col in 1..Largeur loop - -- Il suffit de tracer les lignes impaires et les colonnes impaires. - if (Ligne mod 2 = 1) or (Col mod 2 = 1) then - Txt.Put("#") ; - else - Txt.Put(" ") ; - end if ; + for Ligne in 1..Hauteur loop + for Col in 1..Largeur loop + -- Il suffit de tracer les lignes impaires et les colonnes impaires. + if (Ligne mod 2 = 1) or (Col mod 2 = 1) then + Txt.Put("#") ; + else + Txt.Put(" ") ; + end if ; + end loop ; + Txt.New_Line ; end loop ; Txt.New_Line ; - end loop ; - Txt.New_Line ; - end Tracer_Quadrillage ; + end Tracer_Quadrillage ; - procedure Tracer_Damier (Largeur : Integer ; Hauteur : Integer) is - begin + procedure Tracer_Damier (Largeur : Integer ; Hauteur : Integer) is + begin -- Même principe que Tester_Quadrillage - for Ligne in 1..Hauteur loop - for Col in 1..Largeur loop - -- Il suffit de tracer les cases telles que x+y est pair. - if (Ligne + Col) mod 2 = 0 then - Txt.Put("#") ; - else - Txt.Put(" ") ; - end if ; + for Ligne in 1..Hauteur loop + for Col in 1..Largeur loop + -- Il suffit de tracer les cases telles que x+y est pair. + if (Ligne + Col) mod 2 = 0 then + Txt.Put("#") ; + else + Txt.Put(" ") ; + end if ; + end loop ; + Txt.New_Line ; end loop ; Txt.New_Line ; - end loop ; - Txt.New_Line ; - end Tracer_Damier ; + end Tracer_Damier ; - procedure Tracer_Gros_Damier (Largeur : Integer ; Hauteur : Integer) is - begin + procedure Tracer_Gros_Damier (Largeur : Integer ; Hauteur : Integer) is + begin -- Même principe, mais en divisant les coordonnées par 2 pour faire des paquets de 2x2. - for Ligne in 1..Hauteur loop - for Col in 1..Largeur loop + for Ligne in 1..Hauteur loop + for Col in 1..Largeur loop - -- On soustrait 1 car sinon le damier commence au milieu d'un paquet de 2x2 et ce n'est pas joli. - if ((Ligne-1)/2 + (Col-1)/2) mod 2 = 1 then - Txt.Put("#") ; - else - Txt.Put(" ") ; - end if ; + -- On soustrait 1 car sinon le damier commence au milieu d'un paquet de 2x2 et ce n'est pas joli. + if ((Ligne-1)/2 + (Col-1)/2) mod 2 = 1 then + Txt.Put("#") ; + else + Txt.Put(" ") ; + end if ; + end loop ; + Txt.New_Line ; end loop ; Txt.New_Line ; - end loop ; - Txt.New_Line ; - end Tracer_Gros_Damier ; + end Tracer_Gros_Damier ; - begin +begin - Txt.Put_Line("Test de Tracer_Ligne : ") ; - Txt.New_Line ; + Txt.Put_Line("Test de Tracer_Ligne : ") ; + Txt.New_Line ; - Tracer_Ligne(3) ; - Tracer_Ligne(8) ; - Tracer_Ligne(20) ; + Tracer_Ligne(3) ; + Tracer_Ligne(8) ; + Tracer_Ligne(20) ; - Txt.New_Line ; - Txt.Put_Line("Test de Tracer_Rectangle : ") ; - Txt.New_Line ; + Txt.New_Line ; + Txt.Put_Line("Test de Tracer_Rectangle : ") ; + Txt.New_Line ; - Tracer_Rectangle(5, 5) ; - Tracer_Rectangle(14, 2) ; - Tracer_Rectangle(4, 6) ; + Tracer_Rectangle(5, 5) ; + Tracer_Rectangle(14, 2) ; + Tracer_Rectangle(4, 6) ; - Txt.New_Line ; - Txt.Put_Line("Test de Tracer_Quadrillage : ") ; - Txt.New_Line ; + Txt.New_Line ; + Txt.Put_Line("Test de Tracer_Quadrillage : ") ; + Txt.New_Line ; - Tracer_Quadrillage(19, 11) ; + Tracer_Quadrillage(19, 11) ; - Txt.New_Line ; - Txt.Put_Line("Test de Tracer_Damier : ") ; - Txt.New_Line ; + Txt.New_Line ; + Txt.Put_Line("Test de Tracer_Damier : ") ; + Txt.New_Line ; - Tracer_Damier(18, 10) ; + Tracer_Damier(18, 10) ; - Txt.New_Line ; - Txt.Put_Line("Test de Tracer_Gros_Damier : ") ; - Txt.New_Line ; + Txt.New_Line ; + Txt.Put_Line("Test de Tracer_Gros_Damier : ") ; + Txt.New_Line ; - Tracer_Gros_Damier(18, 10) ; + Tracer_Gros_Damier(18, 10) ; - end Mission1 ; -
- - - - +
end Mission1 ; +
\ No newline at end of file diff --git a/Y/Ada-S2/Programmes/exos-preparatoires/mission2.html b/Y/Ada-S2/Programmes/exos-preparatoires/mission2.html index d179533..574d478 100644 --- a/Y/Ada-S2/Programmes/exos-preparatoires/mission2.html +++ b/Y/Ada-S2/Programmes/exos-preparatoires/mission2.html @@ -1,135 +1,95 @@ - +mission2.adb
with Gada.Text_IO ; - - mission2.adb - - - - +procedure Mission2 is - - -
- with Gada.Text_IO ; + package Txt renames Gada.Text_IO ; - procedure Mission2 is - - package Txt renames Gada.Text_IO ; - - type T_Intervalle is record + type T_Intervalle is record Inf : Float ; - Sup : Float ; - end record ; + Sup : Float ; + end record ; + + function Intervalle_Image(A : T_Intervalle) return String is + begin + return "[" & Integer'Image(Integer(A.Inf)) & "," & Integer'Image(Integer(A.Sup)) & "]" ; + end Intervalle_Image ; - function Intervalle_Image(A : T_Intervalle) return String is - begin - return "[" & Integer'Image(Integer(A.Inf)) & "," & Integer'Image(Integer(A.Sup)) & "]" ; - end Intervalle_Image ; - - -- A est inclus dans B <=> les bornes de A sont comprises entre les bornes de B. - function Est_Inclus (A : T_Intervalle ; B : T_Intervalle) return Boolean is - begin + -- A est inclus dans B <=> les bornes de A sont comprises entre les bornes de B. + function Est_Inclus (A : T_Intervalle ; B : T_Intervalle) return Boolean is + begin return A.Inf >= B.Inf and A.Sup <= B.Sup ; - end Est_Inclus ; + end Est_Inclus ; - -- A et B disjoints <=> A est situé avant B ou A est situé après B. - function Disjoints (A : T_Intervalle ; B : T_Intervalle) return Boolean is - begin + -- A et B disjoints <=> A est situé avant B ou A est situé après B. + function Disjoints (A : T_Intervalle ; B : T_Intervalle) return Boolean is + begin return A.Sup < B.Inf or A.Inf > B.Sup ; - end Disjoints ; + end Disjoints ; - procedure Afficher_Relation (A : T_Intervalle ; B : T_Intervalle) is - begin + procedure Afficher_Relation (A : T_Intervalle ; B : T_Intervalle) is + begin if Est_Inclus(A, B) then - Txt.Put_Line(Intervalle_Image(A) & " est inclus dans " & Intervalle_Image(B)) ; + Txt.Put_Line(Intervalle_Image(A) & " est inclus dans " & Intervalle_Image(B)) ; elsif Est_Inclus(B,A) then - Txt.Put_Line(Intervalle_Image(B) & " est inclus dans " & Intervalle_Image(A)) ; + Txt.Put_Line(Intervalle_Image(B) & " est inclus dans " & Intervalle_Image(A)) ; elsif Disjoints(A,B) then - Txt.Put_Line(Intervalle_Image(A) & " et " & Intervalle_Image(B) - & " sont disjoints.") ; + Txt.Put_Line(Intervalle_Image(A) & " et " & Intervalle_Image(B) & " sont disjoints.") ; else - Txt.Put_Line(Intervalle_Image(A) & " et " & Intervalle_Image(B) - & " ne sont pas disjoints.") ; + Txt.Put_Line(Intervalle_Image(A) & " et " & Intervalle_Image(B) & " ne sont pas disjoints.") ; end if ; - end Afficher_Relation ; + end Afficher_Relation ; - type T_Prod is record + type T_Prod is record Gauche : T_Intervalle ; Droite : T_Intervalle ; - end record ; + end record ; + + function Prod_Image(A : T_Prod) return String is + begin + return Intervalle_Image(A.Gauche) & " x " & Intervalle_Image(A.Droite) ; + end Prod_Image ; + + + -- A1xA2 est inclus dans B1xB2 <=> A1 inclus dans B1 et A2 inclus dans B2 + function Prod_Est_Inclus (A : T_Prod ; B : T_Prod) return Boolean is + begin + return Est_Inclus (A.Gauche, B.Gauche) and Est_Inclus(A.Droite, B.Droite) ; + end Prod_Est_Inclus ; - function Prod_Image(A : T_Prod) return String is - begin - return Intervalle_Image(A.Gauche) & " x " & Intervalle_Image(A.Droite) ; - end Prod_Image ; + -- A1xA2 disjoint de B1xB2 <=> A1 disjoint de B1 ou A2 disjoint de B2 + function Prod_Disjoints (A : T_Prod ; B : T_Prod) return Boolean is + begin + return Disjoints(A.Gauche, B.Gauche) or Disjoints(A.Droite, B.Droite) ; + end Prod_Disjoints ; - - -- A1xA2 est inclus dans B1xB2 <=> A1 inclus dans B1 et A2 inclus dans B2 - function Prod_Est_Inclus (A : T_Prod ; B : T_Prod) return Boolean is - begin - return Est_Inclus (A.Gauche, B.Gauche) and Est_Inclus(A.Droite, B.Droite) ; - end Prod_Est_Inclus ; - - -- A1xA2 disjoint de B1xB2 <=> A1 disjoint de B1 ou A2 disjoint de B2 - function Prod_Disjoints (A : T_Prod ; B : T_Prod) return Boolean is - begin - return Disjoints(A.Gauche, B.Gauche) or Disjoints(A.Droite, - B.Droite) ; - end Prod_Disjoints ; - - procedure Prod_Afficher_Relation (A : T_Prod ; B : T_Prod) is - begin + procedure Prod_Afficher_Relation (A : T_Prod ; B : T_Prod) is + begin if Prod_Est_Inclus(A, B) then - Txt.Put_Line(Prod_Image(A) & " est inclus dans " & Prod_Image(B)) ; + Txt.Put_Line(Prod_Image(A) & " est inclus dans " & Prod_Image(B)) ; elsif Prod_Est_Inclus(B,A) then - Txt.Put_Line(Prod_Image(B) & " est inclus dans " & Prod_Image(A)) ; + Txt.Put_Line(Prod_Image(B) & " est inclus dans " & Prod_Image(A)) ; elsif Prod_Disjoints(A,B) then - Txt.Put_Line(Prod_Image(A) & " et " & Prod_Image(B) & " sont disjoints.") ; + Txt.Put_Line(Prod_Image(A) & " et " & Prod_Image(B) & " sont disjoints.") ; else - Txt.Put_Line(Prod_Image(A) & " et " & Prod_Image(B) & " ne sont pas disjoints.") ; + Txt.Put_Line(Prod_Image(A) & " et " & Prod_Image(B) & " ne sont pas disjoints.") ; end if ; - end Prod_Afficher_Relation ; + end Prod_Afficher_Relation ; - C : constant T_Intervalle := (5.0, 10.0) ; - D : constant T_Intervalle := (7.0, 8.0) ; - E : constant T_Intervalle := (4.0, 6.0) ; + C : constant T_Intervalle := (5.0, 10.0) ; + D : constant T_Intervalle := (7.0, 8.0) ; + E : constant T_Intervalle := (4.0, 6.0) ; - begin +begin Afficher_Relation(C,D) ; Afficher_Relation(D,C) ; Afficher_Relation(C,E) ; Afficher_Relation(D,E) ; - Prod_Afficher_Relation((C, C), (D, D)) ; + Prod_Afficher_Relation((C, C), (D, D)) ; Prod_Afficher_Relation((C, D), (D, C)) ; Prod_Afficher_Relation((D, C), (E, C)) ; - end Mission2 ; - -
- - - - +end Mission2 ; +
\ No newline at end of file diff --git a/Y/Ada-S2/Programmes/exos-preparatoires/solution-en-ocaml.html b/Y/Ada-S2/Programmes/exos-preparatoires/solution-en-ocaml.html index 2d66ed2..3cfc3d1 100644 --- a/Y/Ada-S2/Programmes/exos-preparatoires/solution-en-ocaml.html +++ b/Y/Ada-S2/Programmes/exos-preparatoires/solution-en-ocaml.html @@ -1,80 +1,63 @@ - + + +mission2.ml
(* Version OCaml de l'exercice sur les intervalles *) - - mission2.ml - - - - +type t_intervalle = + { inf: float ; + sup: float } - - -
(* Version OCaml de l'exercice sur les intervalles *) +let sof x = string_of_int (int_of_float x) - type t_intervalle = - { inf: float ; - sup: float } +(* Les trois premières fonctions demandées. *) +let intervalle_image it = "[" ^ sof it.inf ^ ", " ^ sof it.sup ^ "]" +let est_inclus a b = (a.inf >= b.inf && a.sup <= b.sup) +let disjoints a b = (a.sup < b.inf || a.inf > b.sup) - let sof x = string_of_int (int_of_float x) +(* Fonction d'affichage générique qui marchera pour t_intervalle et pour t_prod. *) +let affichage_gen f_inclus f_disjoint f_image i1 i2 = + let s1 = f_image i1 + and s2 = f_image i2 in + + if f_inclus i1 i2 then Printf.printf "%s est inclus dans %s\n" s1 s2 + else if f_inclus i2 i1 then Printf.printf "%s est inclus dans %s\n" s2 s1 + else if f_disjoint i1 i2 then Printf.printf "%s et %s sont disjoints\n" s1 s2 + else Printf.printf "%s et %s ne sont pas disjoints, ni inclus\n" s1 s2 - (* Les trois premières fonctions demandées. *) - let intervalle_image it = "[" ^ sof it.inf ^ ", " ^ sof it.sup ^ "]" - let est_inclus a b = (a.inf >= b.inf && a.sup <= b.sup) - let disjoints a b = (a.sup < b.inf || a.inf > b.sup) +(* Afficher_relation pour les intervalles. *) +let afficher_relation = affichage_gen est_inclus disjoints intervalle_image - (* Fonction d'affichage générique qui marchera pour t_intervalle et pour t_prod. *) - let affichage_gen f_inclus f_disjoint f_image i1 i2 = - let s1 = f_image i1 - and s2 = f_image i2 in +(* Produit cartésien *) +type t_prod = + { left: t_intervalle ; + right: t_intervalle } - if f_inclus i1 i2 then Printf.printf "%s est inclus dans %s\n" s1 s2 - else if f_inclus i2 i1 then Printf.printf "%s est inclus dans %s\n" s2 s1 - else if f_disjoint i1 i2 then Printf.printf "%s et %s sont disjoints\n" s1 s2 - else Printf.printf "%s et %s ne sont pas disjoints, ni inclus\n" s1 s2 +(* Les trois premières fonctions pour les produits cartésiens. *) +let prod_image p = intervalle_image p.left ^ " x " ^ intervalle_image p.right +let prod_est_inclus a b = est_inclus a.left b.left && est_inclus a.right b.right +let prod_disjoints a b = disjoints a.left b.left || disjoints a.right b.right - (* Afficher_relation pour les intervalles. *) - let afficher_relation = affichage_gen est_inclus disjoints intervalle_image +(* La fonction d'affichage demandée. *) +let prod_afficher_relation = affichage_gen prod_est_inclus prod_disjoints prod_image - (* Produit cartésien *) - type t_prod = - { left: t_intervalle ; - right: t_intervalle } +let prod a b = { left = a ; right = b } + +(* Test *) +let () = + let c = { inf = 5.0 ; sup = 10.0 } + and d = { inf = 7.0 ; sup = 8.0 } + and e = { inf = 4.0 ; sup = 6.0 } + in - (* Les trois premières fonctions pour les produits cartésiens. *) - let prod_image p = intervalle_image p.left ^ " x " ^ intervalle_image p.right - let prod_est_inclus a b = est_inclus a.left b.left && est_inclus a.right b.right - let prod_disjoints a b = disjoints a.left b.left || disjoints a.right b.right + afficher_relation c d ; + afficher_relation d c ; + afficher_relation c e ; + afficher_relation d e ; - (* La fonction d'affichage demandée. *) - let prod_afficher_relation = affichage_gen prod_est_inclus prod_disjoints prod_image + prod_afficher_relation (prod c c) (prod d d) ; + prod_afficher_relation (prod c d) (prod d c) ; + prod_afficher_relation (prod d c) (prod e c) ; + () - let prod a b = { left = a ; right = b } - - (* Test *) - let () = - let c = { inf = 5.0 ; sup = 10.0 } - and d = { inf = 7.0 ; sup = 8.0 } - and e = { inf = 4.0 ; sup = 6.0 } - in - - afficher_relation c d ; - afficher_relation d c ; - afficher_relation c e ; - afficher_relation d e ; - - prod_afficher_relation (prod c c) (prod d d) ; - prod_afficher_relation (prod c d) (prod d c) ; - prod_afficher_relation (prod d c) (prod e c) ; - () - - -
- - - - + +
\ No newline at end of file