Przeglądaj źródła

Last commit before leaving

Ghastrod 1 rok temu
rodzic
commit
5a97f160b8

+ 6 - 0
MP/.vscode/settings.json

@@ -0,0 +1,6 @@
+{
+    "ocaml.sandbox": {
+        "kind": "opam",
+        "switch": "cours"
+    }
+}

+ 0 - 0
MP/CCP2022.ml


+ 176 - 0
MP/JALLAT_DS2.ml

@@ -0,0 +1,176 @@
+type ensemble = int list;;
+
+(*Insérer dans un ensemble*)
+
+let rec insere x (e:ensemble) = match e with
+| [] -> [x]
+| t::q -> if t=x then e else t::(insere x q);;
+
+(*Evaluation de la complexité, en fonction du nombre d'éléments de E, ne prendra en compte*)
+(*que le nombre d'appels récursifs*)
+(*Complexité linéaire*)
+
+(*Recherche dans un ensemble*)
+let rec recherche x (e:ensemble) = match e with
+| [] -> false
+| t::q -> if t=x then true else recherche x q;;
+
+(*Exemples de valeurs pour x et e, tels que l'on soit dans le pire ou le meilleur des cas*)
+(*x = 1, e = [1;2;3;4;5;6;7;8;9;10]*)
+(*x = 11, e = [1;2;3;4;5;6;7;8;9;10]*)
+
+(*Complexité linéaire*)
+
+(*Nous travaillons avec des arbres binaires entiers*)
+
+(*Profondeur d'un arbre avec la profondeur du sous-arbre gauche, noté G, et la profondeur du sous-arbre*)
+(*droit, noté D*)
+(*Si l'arbre est l'arbre vide, alors sa profondeur est de zéro*)
+(*Sinon, c'est le maximum entre la profondeur du sous-arbre gauche et celle du droit, +1*)
+
+
+(*On définit un arbre binaire d'entiers, par le déséquilibre du noeud, son sous-fil gauche, l'étiquette associé*)
+(*à la racine, puis le sous-fil droit*)
+type arbre = Vide | Noeud of int * arbre * int * arbre;;
+
+let ex1 = Noeud(0,
+Noeud(-1,
+Vide,
+9,
+Noeud(0,Vide,6,Vide)),
+7,
+Noeud(1,
+Noeud(0,Vide,3,Vide),
+8,
+Vide));;
+(*Troisième arbre de l'exemple II.3*)
+let ex3 = Noeud(-1, Noeud(0, Noeud(0, Vide, 1, Vide), 3, Noeud(0,Vide,4,Vide)), 6, 
+Noeud(1,Noeud(-1,Vide,7,Noeud(0,Vide,8,Vide)),9,Noeud(0,Vide,10,Vide)));;
+
+let rec profondeur a = match a with
+| Vide -> 0
+| Noeud(_,g,_,d) -> 1 + max (profondeur g) (profondeur d);;
+
+profondeur ex1;;
+
+let rec valider_decoration a = match a with
+| Vide -> true
+| Noeud(deco,g,_,d) -> ((profondeur g) - (profondeur d)) = deco && valider_decoration g && valider_decoration d;;
+;;
+
+valider_decoration ex1;;
+
+(*Estimation de la complexité, en fonction du nombre d'appels récursifs*)
+
+(*Complexité logarithmique*)
+
+(*On considère des arbres binaires de recherche*)
+
+(*Je crée une fonction auxiliaire racine, ce qui me permet d'observer la racine des sous-arbres*)
+(*On considère des entiers naturels strictement positifs, donc Vide ne renvoit rien*)
+let rec racine a = match a with
+| Vide -> failwith "Arbre vide"
+| Noeud(_,g,e,d) -> e;;
+
+racine ex1;;
+racine ex3;;
+
+let rec valider_abr a = match a with
+| Vide -> true
+| Noeud(_,Vide,_,Vide) -> true
+| Noeud(_,Vide,_,d) -> (racine d) > (racine a) && valider_abr d
+| Noeud(_,g,_,Vide) -> (racine g) < (racine a) && valider_abr g
+| Noeud(_,g,_,d) -> (racine g) < (racine a) && (racine d) > (racine a) && valider_abr g && valider_abr d;;
+
+valider_abr ex3;;
+
+let rec recherche_abr x a = match a with
+| Vide -> false
+| Noeud(_,g,e,d) -> if x=e then true else if x<e then recherche_abr x g else recherche_abr x d;;
+
+recherche_abr 1 ex3;;
+
+(*Exemples de valeurs de paramètres de x et a pour les meilleurs et pires cas*)
+(*x = 6, a = ex3*)
+(*x = 11, a = ex3*)
+
+(*Evaluation de la complexité, en fonction du nombre d'appels récursifs*)
+
+(*Complexité logarithmique*)
+
+(*Insertion dans un ABR*)
+(*Cette fonction doit calculer le nouveau déséquilibre pour les noeuds où il change*)
+let rec insere_abr x a = match a with
+| Vide -> Noeud(0,Vide,x,Vide)
+| Noeud(deco,g,e,d) -> if x=e then a else if x<e then Noeud(deco+1,insere_abr x g,e,d) else Noeud(deco-1,g,e,insere_abr x d);;
+
+insere_abr 11 ex3;;
+
+(*Exemples de valeurs de paramètres de x et a pour les meilleurs et pires cas*)
+(*x = 6, a = ex3*)
+(*x = 11, a = ex3*)
+
+(*Evaluation de la complexité, en fonction du nombre d'appels récursifs*)
+
+(*Complexité logarithmique*)
+
+(*Rotations d'un ABR*)
+
+(*Rotation simple de type D*)
+let rec rotationSD a = match a with
+| Vide -> failwith "Arbre vide"
+| Noeud(_,Vide,_,_) -> failwith "Rotation impossible"
+| Noeud(_,Noeud(_,Vide,_,_),_,_) -> failwith "Rotation impossible"
+| Noeud(_,Noeud(_,Noeud(_,Vide,_,_),_,_),_,_) -> failwith "Rotation impossible"
+| Noeud(_,Noeud(_,Noeud(_,g1,e1,d1),e2,d2),e3,d3) -> Noeud(0,g1,e1,Noeud(0,d1,e2,Noeud(0,d2,e3,d3)));;
+
+(*Rotation simple de type G*)
+let rec rotationSG a = match a with
+| Vide -> failwith "Arbre vide"
+| Noeud(_,_,_,Vide) -> failwith "Rotation impossible"
+| Noeud(_,_,_,Noeud(_,_,_,Vide)) -> failwith "Rotation impossible"
+| Noeud(_,_,_,Noeud(_,_,_,Noeud(_,_,_,Vide))) -> failwith "Rotation impossible"
+| Noeud(_,g3,e3,Noeud(_,g2,e2,Noeud(_,g1,e1,d1))) -> Noeud(0,Noeud(0,Noeud(0,g3,e3,g2),e2,g1),e1,d1);;
+
+(*Rotation double de type D*)
+let rec rotationDD a = match a with
+| Vide -> failwith "Arbre vide"
+| Noeud(_,Vide,_,_) -> failwith "Rotation impossible"
+| Noeud(_,Noeud(_,Vide,_,_),_,_) -> failwith "Rotation impossible"
+| Noeud(_,Noeud(_,Noeud(_,Vide,_,_),_,_),_,_) -> failwith "Rotation impossible"
+| Noeud(_,Noeud(_,Noeud(_,g1,e1,d1),e2,d2),e3,d3) -> Noeud(0,Noeud(0,g1,e1,Noeud(0,d1,e2,d2)),e3,d3);;
+
+(*Rotation double de type G*)
+let rec rotationDG a = match a with
+| Vide -> failwith "Arbre vide"
+| Noeud(_,_,_,Vide) -> failwith "Rotation impossible"
+| Noeud(_,_,_,Noeud(_,_,_,Vide)) -> failwith "Rotation impossible"
+| Noeud(_,_,_,Noeud(_,_,_,Noeud(_,_,_,Vide))) -> failwith "Rotation impossible"
+| Noeud(_,g3,e3,Noeud(_,g2,e2,Noeud(_,g1,e1,d1))) -> Noeud(0,Noeud(0,g3,e3,Noeud(0,g2,e2,d1)),e1,d1);;
+
+
+(*On considère des arbres qui sont en plus équilibrés*)
+(*Donner les différentes formes possibles pour le noeud déséquilibré le plus profond produit lors de*)
+(*l'insertion d'une nouvelle étiquette dans un arbre binaire équilibré en précisant la valeur du déséquilibre*)
+(*de ce noeud*)
+
+
+(*Equilibrage d'un arbre*)
+(*equilibrage a, a un abr dont la racine est déséquilibré, mais dont les sous-fils sont équilibrés*)
+
+let equilibrage a = match a with
+| Vide -> failwith "Arbre vide"
+| Noeud(_,Vide,_,_) -> failwith "Arbre équilibré"
+| Noeud(_,Noeud(_,Vide,_,_),_,_) -> failwith "Arbre équilibré"
+| Noeud(_,Noeud(_,Noeud(_,Vide,_,_),_,_),_,_) -> failwith "Arbre équilibré"
+| Noeud(_,Noeud(_,Noeud(_,g1,e1,d1),e2,d2),e3,d3) -> if (profondeur g1) > (profondeur d1) then rotationSD a else rotationDD a;;
+
+equilibrage ex3;;
+
+(*Insertion dans un ABR équilibré*)
+(*On réequilibre à chaque fois*)
+let rec insere_abr_equilibre x a = match a with
+| Vide -> Noeud(0,Vide,x,Vide)
+| Noeud(deco,g,e,d) -> if x=e then a 
+            else if x<e then equilibrage (Noeud(deco+1,insere_abr_equilibre x g,e,d)) 
+            else equilibrage (Noeud(deco-1,g,e,insere_abr_equilibre x d));;

+ 130 - 0
MP/JALLAT_backtracking.ml

@@ -0,0 +1,130 @@
+let rec creer_nuage_aux x l = match x with
+| 0 -> []
+| _ -> (Random.float 10., Random.float 10.)::(creer_nuage_aux (x-1) l);;
+
+let creer_nuage x = creer_nuage_aux x [];;
+let nuage1_list = creer_nuage 10;;
+let nuage1_array = Array.of_list nuage1_list;;
+type nuage = float*float array;;
+
+
+let point_extremal nuage = let n = Array.length nuage and  aux = ref (snd nuage.(0)) in
+  for i = 1 to n-1 do
+    for j = 0 to 1 do
+      if snd (nuage.(i)) < !aux then aux := snd (nuage.(i))
+  done;
+done;
+;;
+
+let virage_a_gauche point1 point2 point3 = let (x1,y1) = point1 and (x2,y2) = point2 and (x3,y3) = point3 in
+
+;;
+
+type element = Vide | Fixe of int | Variable of int;;
+let grille = element array array;;
+let taille = 9;;
+
+let int_of_element (elt:element):int =
+  match elt with
+  | Vide -> failwith "case vide"
+  | Fixe x -> x
+  | Variable x -> x
+;;
+
+let case_suivante ((a,b):int*int): int*int =
+  if b < taille - 1 then (a,b+1) else (a+1,0)
+;;
+
+let case_precedente ((a,b):int*int):int*int =
+  if b>0 then (a,b-1) else (a-1,taille-1)
+;;
+
+let valeurs_interdites_ligne (g:grille) ((i,j):int*int) : int list =
+  let l = ref [] in
+    for y = 0 to taille - 1 do
+      if (y<>j) && (g.(i)(y)<> Vide) then
+        then l := (int_of_element g.(i).(y)) :: l
+    done;
+    !l
+;;
+
+let valeurs_interdites_colonne (g:grille) ((i,j):int*int) : int list =
+  let l = ref [] in
+    for x = 0 to taille - 1 do
+      if (x<>i) && (g.(x)(j)<> Vide) then
+        then l := (int_of_element g.(x).(j)) :: l
+    done;
+    !l
+;;
+
+let valeurs_interdites_blocs (g:grille) ((i,j):int*int) : int list =
+  let l = ref [] and ib = 3 *(i/3) and jb = 3*(j/3) in
+    for x = ib to ib+2 do
+      for y = jb to jb+2 do
+      if ((x,y)<>(i,j)) && (g.(x)(y)<> Vide) then
+        then l := (int_of_element g.(x).(j)) :: l
+    done;
+  done;
+    !l
+;;
+
+let valeur_test (g:grille) ((i,j):int*int) : int list =
+  let vil = valeurs_interdites_ligne g (i,j) and
+      vib = valeurs_interdites_blocs g (i,j) and
+      vic = valeurs_interdites_colonne g (i,j) and
+      l = ref [] in
+    for a = 1 to taille -1 do
+      if not ((List.mem a vil) || (List.mem a vic) || (List.mem a vib)) then
+        l:= a::!l
+    done;
+    !l
+;;
+
+let est_fixe (g:grille) ((i,j):int*int):bool =
+  match g.(i).(j) with
+  | Fixe _ -> true
+  | _ -> false
+;;
+
+let sudoku g =
+  let i = ref 0 and j = ref 0 and
+  g_test = Array.make_matrix taille taille [] in
+  if not (est_fixe g (0,0)) then
+    g_test.(0).(0)<- valeur_test g (0,0);
+  while (!i>-1) && (!i<taille) do
+    if (est_fixe g (!i,!j))
+      then
+        begin
+          let (x,y) = case_suivante (!i,!j) in
+            if (x<taille) && (not(est_fixe g (x,y)))
+              then g_test(!i).(!j)<- valeur_test g (x,y);
+            i := x;
+            j := y
+        end
+      else
+        begin
+          if (g_test.(!i).(!j) = [])
+            then
+              begin
+                while (!i > -1) && (((est_fixe g (!i,!j))) || (g_test.(!i).(!j) = [])) do
+                  if not(est_fixe g (!i,!j)) then g.(!i).(!j)<- Vide
+                  let (x,y) = case_precedente (!i,!j) in
+                  i:=x;
+                  j:=y;
+                done;
+              end;
+          else
+            begin
+              g.(!i).(!j) <- Variable(List.hd g_test.(!i).(!j));
+              g_test.(!i).(!j) <- List.tl g_test.(!i).(!j);
+              let (x,y) = case_suivante (!i,!j) in
+                if (x<taille) && (not (est_fixe g (x,y)))
+                  then g_test.(x).(y) <- valeur_test g (x,y)
+              i:=x;
+              j:=y;
+            end
+          end
+        done;
+        g
+;;
+

+ 71 - 0
MP/JALLAT_kruskal4.ml

@@ -0,0 +1,71 @@
+type 'a poids = Poids of 'a | Infini;;
+
+let g_ex = [|[1;3];[0;2;3;4];[1;4];[0;1;4;5];[1;2;3;5;6];[3;4;6];[4;5]|] ;;
+
+let w_ex = [|[|Infini;Poids 7;Infini;Poids 5;Infini;Infini;Infini|];
+             [|Poids 7;Infini;Poids 8;Poids 9;Poids 7;Infini;Infini|];
+             [|Infini;Poids 8;Infini;Infini;Poids 5;Infini;Infini|];
+             [|Poids 5;Poids 9;Infini;Infini;Poids 15;Poids 6;Infini|];
+             [|Infini;Poids 7;Poids 5;Poids 15;Infini;Poids 8;Poids 9|];
+             [|Infini;Infini;Infini;Poids 6;Poids 8;Infini;Poids 11|];
+             [|Infini;Infini;Infini;Infini;Poids 9;Poids 11;Infini|]
+|] ;;
+
+(*Schema classique de tri par insertion, version recursif*)
+(*Bien penser que les éléments de la liste et x sont des couples, représentant les arretes*)
+let rec insertion_liste_triee (w: int poids array array) (l: 'a list) (x : 'a) : 'a list 
+  = match l with
+  | [] -> [x]
+  | (t1,t2)::q -> if w.(x).(t1) <= w.(x).(t2) then x::l else (t1,t2)::(insertion_liste_triee w q x)
+;;
+
+let liste_triee_arrete w = 
+  let n = Array.length w and l = ref [] in
+  for i=0 to n-1 do
+    for j=i+1 to n-1 do
+      (*si l'arrete existe, alors seulement on l'insere, on va pas chercher à insérer des arretes qui n'existe pas*)
+      if w.(i).(j) <> Infini then l := insertion_liste_triee w !l (i,j)
+    done
+  done;
+  !l
+;;
+
+liste_triee_arrete w_ex;;
+
+(*Sert à remettre toutes les composantes connexes dans le tableau représentant les composantes connexes*)
+(*Est donc utilisé dès que l'on rajoute une arrête qui ne crée pas de cycle*)
+let maj_composantes compo i j =
+  let n = Array.length compo and ci = compo.(i) and cj = compo.(j) in
+    for k=0 to n-1 do
+      if compo.(k) = cj then compo.(k) <- ci
+    done
+;;
+(*Recursive terminale, qui va checker si ça crée un cycle, puis ajouter l'arrete sinon*)
+let rec kruskal1_aux compo liste_triee acc = match liste_triee with
+(*Si la liste est vide, on a fini, on renvoie l'acc, structure de récursive terminale*)
+| [] -> acc
+(*Si la liste n'est pas vide, on va regarder si l'arrete crée un cycle*)
+(*Si elle crée un cycle, on passe à l'arrete suivante*)
+(*Sinon, on ajoute l'arrete à l'acc, et on met à jour les composantes connexes*)
+(*On rappelle la fonction avec la liste_triee sans l'arrete ajoutée, et l'acc avec l'arrete ajoutée*)
+|(t1,t2)::q -> if compo.(x) = compo.(y) then
+    begin
+      kruskal1_aux compo q acc
+    end
+  else
+    begin
+      maj_composantes compo x y;
+      kruskal1_aux compo q ((t1,t2)::acc)
+    end
+;;
+
+(*Fonction chapeau, qui va tout d'abord créer un tableau des composantes connexes, que j'ai nommé compo*)
+(*cette petite function ajoute chaque point à sa propre composante connexe*)
+(*puis ont ajoute récursivement les arrêtes, tout en vérifiant qu'elles ne créent pas de cycle*)
+(*Travail effectué par kruskal1_aux*)
+let kruskal1 (w: int poids array array) : (int * int) list =
+  let n = Array.length w and compo = Array.init n (fun i -> i) in
+  let liste_triee = liste_triee_arrete w in
+  kruskal1_aux compo liste_triee []
+;;
+

+ 93 - 0
MP/JALLAT_kurska.ml

@@ -0,0 +1,93 @@
+type 'a poids = Poids of 'a | Infini;;
+
+let g = [|
+  [|Infini; Poids(9); Infini; Poids(5); Infini; Infini; Infini|];
+  [|Poids(7); Infini; Poids(8); Poids(9); Poids(7); Infini; Infini|];
+  [|Infini; Poids(8); Infini; Infini; Poids(5); Infini; Infini|];
+  [|Poids(5); Poids(9); Infini; Infini; Poids(15); Poids(6); Infini|];
+  [|Infini; Poids(7); Poids(5); Poids(15); Infini; Poids(8); Poids(9)|];
+  [|Infini; Infini; Infini; Poids(6); Poids(8); Infini; Poids(11)|];
+  [|Infini; Infini; Infini; Infini; Poids(9); Poids(11); Infini|];
+|];;
+
+let rec insere i x l =
+  match l with
+  | [] -> [i]
+  | t::q -> if x > t then i :: l else t :: (insere i x q)
+;;
+
+let liste_triee_arrete w =
+  let l = ref [] and n = Array.length w.(0) in
+  for i = 0 to n - 2 do
+    for j = i + 1 to (n - 1) do
+      if w.(i).(j) <> Infini then
+        match w.(i).(j) with
+        | Poids(p) -> l := insere (i, j) p !l
+        | Infini -> ()
+      else ()
+    done;
+  done;
+  !l
+;;
+
+let n = Array.length g.(0);;
+let composantes = Array.make n 0;;
+
+let aretes = liste_triee_arrete g;;
+
+let aux i j t =
+  let ci = composantes.(i) and cj = composantes.(j) in
+  match ci = cj with
+  | true -> ()
+  | false ->
+    t := (i, j) :: !t;
+    for k = 0 to n - 1 do
+      if composantes.(k) = cj then composantes.(k) <- ci;
+    done
+;;
+
+let rec kaux1 w aretes t =
+  match aretes with
+  | [] -> t
+  | a::aq -> let (i, j) = a in aux i j t; kaux1 w aq t
+;;
+
+let kruskal1 w =
+  let aretes = liste_triee_arrete w in
+  let t = ref [] in
+  kaux1 w aretes t;
+  !t
+;;
+
+(* Seconde partie *)
+(*une fonction chemin w u v, qui renvoie true s'il existe un chemin entre u et v*)
+let chemin w u v =
+  let n = Array.length w in
+  let rec aux i =
+    match i = n with
+    | true -> false
+    | false ->
+        match w.(u).(i) with
+        | Infini -> aux (i+1)
+        | Poids(p) ->
+            match w.(i).(v) with
+            | Infini -> aux (i+1)
+            | Poids(q) -> true
+  in aux 0
+;;
+
+
+let kruskal2 w =
+  let n = Array.length w in
+  let rec aux i =
+    match i = n with
+    | true -> []
+    | false ->
+        match w.(i) with
+        | [] -> aux (i+1)
+        | t::q ->
+            match chemin w t i with
+            | true -> (t, i) :: (aux (i+1))
+            | false -> aux (i+1)
+  in aux 0
+;;

+ 113 - 0
MP/JALLAT_kurska2.ml

@@ -0,0 +1,113 @@
+type 'a poids = Poids of 'a | Infini;;
+
+let g = [|
+  [|Infini; Poids(9); Infini; Poids(5); Infini; Infini; Infini|];
+  [|Poids(7); Infini; Poids(8); Poids(9); Poids(7); Infini; Infini|];
+  [|Infini; Poids(8); Infini; Infini; Poids(5); Infini; Infini|];
+  [|Poids(5); Poids(9); Infini; Infini; Poids(15); Poids(6); Infini|];
+  [|Infini; Poids(7); Poids(5); Poids(15); Infini; Poids(8); Poids(9)|];
+  [|Infini; Infini; Infini; Poids(6); Poids(8); Infini; Poids(11)|];
+  [|Infini; Infini; Infini; Infini; Poids(9); Poids(11); Infini|];
+|];;
+
+(* Žcrire plut™t Poids 9 que Poids(9) , comme on Žcrit plut™t f x que f(x) *)
+
+let rec insere i x l =
+  match l with
+  | [] -> [i]
+  | t::q -> if x > t then i :: l else t :: (insere i x q)
+;;
+
+(* myst�re ... i sera l'ar�te et x le poids, merci pour les explications ! *)
+(* tu compares x et t , x et t sont donc de m�me type *)
+
+let liste_triee_arrete w =
+  let l = ref [] and n = Array.length w.(0) in
+  for i = 0 to n - 2 do
+    for j = i + 1 to (n - 1) do
+      if w.(i).(j) <> Infini then
+        match w.(i).(j) with
+        | Poids(p) -> (l := insere (i, j) p !l)
+        | Infini -> ()
+      else ()
+    done;
+  done;
+  !l
+;;
+
+(* mauvaise orientation : une liste, tu proposes une fonction rŽcursive et tu Žvites les rŽfŽrences de listes *)
+(* tu tries par ordre dŽcroissant, non ? *)
+(* la fonction insere oblige (i,j) et p ˆ �tre de m�me type, c'est pour �a que w doit etre de type (int*int) ... *)
+(* l'alternative et le filtrage, un peu redondant ... *)
+
+let n = Array.length g.(0);;
+
+let composantes = Array.make n 0;;
+(* tous les sommets sont dans la composante connexe du sommet 0 ? *)
+
+let aretes = liste_triee_arrete g;;
+
+let aux i j t =
+  let ci = composantes.(i) and cj = composantes.(j) in
+  match ci = cj with
+  | true -> ()
+  | false ->
+    t := (i, j) :: !t;
+    for k = 0 to n - 1 do
+      if composantes.(k) = cj then composantes.(k) <- ci;
+    done
+;;
+
+(* t a une valeur avant l'appel ˆ aux, il est modifiŽ pendant aux et il reprend sa valeur initiale apr�s aux,
+la structure d'une rŽfŽrence n'est pas la m�me chose qu'un mutable  *)
+(* la fonction aux devrait renvoyer t *)
+
+let rec kaux1 w aretes t =
+  match aretes with
+  | [] -> t
+  | a::aq -> let (i, j) = a in aux i j t; kaux1 w aq t
+;;
+
+(* recursivitŽ terminale en appelant kaux1 avant (aux i j t) ˆ la place de t *)
+
+let kruskal1 w =
+  let aretes = liste_triee_arrete w in
+  let t = ref [] in
+  kaux1 w aretes t;
+  !t
+;;
+
+(* tu corriges, tu testes et je regarde la suite apr�s et avec des commentaires *)
+
+(* Seconde partie *)
+(*une fonction chemin w u v, qui renvoie true s'il existe un chemin entre u et v*)
+let chemin w u v =
+  let n = Array.length w in
+  let rec aux i =
+    match i = n with
+    | true -> false
+    | false ->
+        match w.(u).(i) with
+        | Infini -> aux (i+1)
+        | Poids(p) ->
+            match w.(i).(v) with
+            | Infini -> aux (i+1)
+            | Poids(q) -> true
+  in aux 0
+;;
+
+
+let kruskal2 w =
+  let n = Array.length w in
+  let rec aux i =
+    match i = n with
+    | true -> []
+    | false ->
+        match w.(i) with
+        | [] -> aux (i+1)
+        | t::q ->
+            match chemin w t i with
+            | true -> (t, i) :: (aux (i+1))
+            | false -> aux (i+1)
+  in aux 0
+;;

+ 109 - 0
MP/JALLAT_kurska3.ml

@@ -0,0 +1,109 @@
+type 'a poids = Poids of 'a | Infini;;
+
+let g = [|
+  [|Infini; Poids(9); Infini; Poids(5); Infini; Infini; Infini|];
+  [|Poids(7); Infini; Poids(8); Poids(9); Poids(7); Infini; Infini|];
+  [|Infini; Poids(8); Infini; Infini; Poids(5); Infini; Infini|];
+  [|Poids(5); Poids(9); Infini; Infini; Poids(15); Poids(6); Infini|];
+  [|Infini; Poids(7); Poids(5); Poids(15); Infini; Poids(8); Poids(9)|];
+  [|Infini; Infini; Infini; Poids(6); Poids(8); Infini; Poids(11)|];
+  [|Infini; Infini; Infini; Infini; Poids(9); Poids(11); Infini|];
+|];;
+
+(* Žcrire plut™t Poids 9 que Poids(9) , comme on Žcrit plut™t f x que f(x) *)
+
+let rec insere i x l =
+  match l with
+  | [] -> [i]
+  | t::q -> if x > t then i :: l else t :: (insere i x q)
+;;
+
+(* myst�re ... i sera l'ar�te et x le poids, merci pour les explications ! *)
+(* tu compares x et t , x et t sont donc de m�me type *)
+
+let liste_triee_arrete w =
+  let l = ref [] and n = Array.length w.(0) in
+  for i = 0 to n - 2 do
+    for j = i + 1 to (n - 1) do
+      if w.(i).(j) <> Infini then
+        match w.(i).(j) with
+        | Poids(p) -> (l := insere (i, j) p !l)
+        | Infini -> ()
+      else ()
+    done;
+  done;
+  !l
+;;
+
+(* mauvaise orientation : une liste, tu proposes une fonction rŽcursive et tu Žvites les rŽfŽrences de listes *)
+(* tu tries par ordre dŽcroissant, non ? *)
+(* la fonction insere oblige (i,j) et p ˆ �tre de m�me type, c'est pour �a que w doit etre de type (int*int) ... *)
+(* l'alternative et le filtrage, un peu redondant ... *)
+
+let n = Array.length g.(0);;
+
+let composantes = Array.make n 0;;
+(* tous les sommets sont dans la composante connexe du sommet 0 ? *)
+
+let aretes = liste_triee_arrete g;;
+
+let aux i j t =
+  let ci = composantes.(i) and cj = composantes.(j) in
+  match ci = cj with
+  | true -> ()
+  | false ->
+    t := (i, j) :: !t;
+    for k = 0 to n - 1 do
+      if composantes.(k) = cj then composantes.(k) <- ci;
+    done
+;;
+
+let rec kaux1 w aretes t =
+  match aretes with
+  | [] -> t
+  | a::aq -> let (i, j) = a in aux i j t; kaux1 w aq t
+;;
+
+(* recursivitŽ terminale en appelant kaux1 avant (aux i j t) ˆ la place de t *)
+
+let kruskal1 w =
+  let aretes = liste_triee_arrete w in
+  let t = ref [] in
+  kaux1 w aretes t;
+  !t
+;;
+
+(* tu corriges, tu testes et je regarde la suite apr�s et avec des commentaires *)
+
+(* Seconde partie *)
+(*une fonction chemin w u v, qui renvoie true s'il existe un chemin entre u et v*)
+let chemin w u v =
+  let n = Array.length w in
+  let rec aux i =
+    match i = n with
+    | true -> false
+    | false ->
+        match w.(u).(i) with
+        | Infini -> aux (i+1)
+        | Poids(p) ->
+            match w.(i).(v) with
+            | Infini -> aux (i+1)
+            | Poids(q) -> true
+  in aux 0
+;;
+
+
+let kruskal2 w =
+  let n = Array.length w in
+  let rec aux i =
+    match i = n with
+    | true -> []
+    | false ->
+        match w.(i) with
+        | [] -> aux (i+1)
+        | t::q ->
+            match chemin w t i with
+            | true -> (t, i) :: (aux (i+1))
+            | false -> aux (i+1)
+  in aux 0
+;;

+ 131 - 0
MP/JALLAT_tas.ml

@@ -0,0 +1,131 @@
+let ex1 = [|0;35;21; 27;15;13;14;9;5;2;7;1;6|];;
+let ex2 = [|35; 21; 27; 15; 13; 14; 9; 5; 2; 7; 1; 6|];;
+
+let est_tas t = let i = ref 0 and n = Array.length t in
+  while (2* !i + 2)<n && t.(!i)>=t.(2 * !i + 1) && t.(!i)<= t.(2 * !i + 2) do
+    i:= !i + 1
+  done;
+  (2* !i + 2) =n && t.(2 * !i +2)<= t.(!i)||(2* !i + 2) =n
+;;
+est_tas ex1;;
+est_tas ex2;;
+let rec est_tas_aux t i n = match i with
+| i when 2 * i+2>n -> true
+| i when 2 * i +2 =n -> t.(2 * i + 2)<= t.(i)
+| _ -> t.(i)>=t.(2 * i + 1) && t.(i)<= t.(2 * i + 2) && est_tas_aux t (i+1) n
+;;
+let est_tas_2 t = est_tas_aux t 0 (Array.length t);;
+est_tas_2 ex1;;
+est_tas_2 ex2;; 
+
+let est_tas_3 t =
+  let n = Array.length t in
+    let i = ref (n-1) in
+      while !i>0 && t.(!i)>=t.((!i-1)/2) do
+        i:= !i - 1
+      done;
+      !i = 0
+;;
+est_tas_3 ex1;;
+est_tas_3 ex2;;
+
+(*Recursif maintenant*)
+
+let rec est_tas_4_aux t i n = match i with
+| i when 2 * i+2>n -> true
+| i when 2 * i +2 =n -> t.(2 * i + 2)<= t.(i)
+| _ -> t.(i)>=t.(2 * i + 1) && t.(i)<= t.(2 * i + 2) && est_tas_4_aux t (i+1) n
+;;
+let est_tas_4 t = est_tas_4_aux t 0 (Array.length t);;
+est_tas_4 ex1;;
+est_tas_4 ex2;;
+
+
+let swap t i j = let temp = t.(i) in
+  t.(i)<-t.(j);
+  t.(j)<-temp
+;;
+
+let rec insere t k x = match k with
+| 0 -> t.(0)<-x
+| _ -> if x<t.((k-1)/2) then t.(k)<-x
+  else 
+    begin
+      (t.(k)<-t.((k-1)/2);
+      insere t ((k-1)/2) x)
+    end;
+;;
+
+let rec insere2 t k x = let n = Array.length t in
+  match k with
+| k when 2 * k+2>n -> t.(k)<-x
+| k when 2 * k+2 = n -> if x>=t.(2*k+1) then t.(k)<-x
+  else
+    begin
+      t.(k)<-t.(2*k+1);
+      t.(2*k+1)<-x
+    end;
+| _ -> let m = if t.(2*k+1)>t.(2*k+2) then 2*k+1 else 2*k+2 in
+  if x>=t.(m) then t.(k)<-x
+  else insere2 t m x
+;;
+
+let remontee_sommets t =
+  for k = 1 to Array.length t - 1 do
+    insere2 t k t.(k)
+  done
+;;
+
+let descente_peres t =
+  let n = Array.length t in
+    for k = n/2-1 downto 0 do
+      percolation_descendante t n k
+    done
+;;
+
+
+type ('a,'b) sommet = {valeur : 'a; mutable priorite : 'b};;
+
+let sommet1_ex = {valeur = 1; priorite = 23};;
+sommet1_ex.priorite <- 24;;
+
+type ('a,'b) file_priorite = {mutable taille : int; tab : ('a,'b) sommet array};;
+
+let n = 10;;
+let creer_file_vide (v,p) =
+  {taille = 0; tab = Array.make n {valeur = v; priorite = p}}
+;;
+
+(*Ajout d'un élément dans la file de priorité*)
+let ajoute f (v,p) =
+  let n = Array.length f.tab in
+    if f.taille = n then failwith "File pleine"
+    else
+      begin
+        f.tab.(f.taille)<-{valeur = v; priorite = p};
+        f.taille<-f.taille+1;
+        remontee_sommets f.tab
+      end
+;;
+
+(*Suppression du sommet de priorité maximale*)
+let supprime_max f =
+  if f.taille = 0 then failwith "File vide"
+  else
+    begin
+      let max = f.tab.(0) in
+        f.tab.(0)<-f.tab.(f.taille-1);
+        f.taille<-f.taille-1;
+        descente_peres f.tab;
+        max
+    end
+;;
+(*Augmentation de la priorité d'un élément dans la file*)
+let augmente_priorite f i p =
+  if i<0 || i>=f.taille then failwith "Indice incorrect"
+  else
+    begin
+      f.tab.(i).priorite<-p;
+      remontee_sommets f.tab
+    end
+;;

+ 40 - 0
MP/JALLAT_tri_topo.ml

@@ -0,0 +1,40 @@
+(*Ce graphe orienté est représenté par une liste de liste, chaque liste donnant l'arrivée des arretes.*)
+(*Dans cet exemple, il existe une arrete de 0 vers 1, donc dans la case 1 du tableau, il y a 0*)
+
+let gex1 = [[];[0];[1;3];[];[3];[2;4];[];[0;1;8];[]];;
+
+let rec tri_topo1_aux : 'a list list -> 'b list -> 'b list =
+  fun g l ->
+    match g with
+    | [] -> l
+    | a :: gs -> tri_topo1_aux gs l
+;;
+
+let tri_topological1 : 'a list list -> 'b list =
+  fun g ->
+    tri_topo1_aux g [];;
+
+tri_topological1 gex1;;
+
+(*On utilise une fonction auxiliaire pour créer le tri topologique*)
+let rec dfs_aux g c i =
+  match g with
+  |[] -> c
+  |t::gs -> if c.(t) = 'B' then dfs_aux gs c i
+            else if c.(t) = 'G' then dfs_aux gs c i
+            else dfs_aux gs (dfs_aux t c i) i
+;;
+let dfs g =
+  let c = Array.make (List.length g) 'B' in
+  dfs_aux g c 0;;
+
+(*utiliser le parcours en profondeur pour créer un tri topologique*)
+let tritopologique2 g =
+  let c = Array.to_list(dfs g) in
+  let rec aux c i =
+    match c with
+    |[] -> []
+    |c::cs -> if c = 'B' then aux cs (i+1)
+              else if c = 'G' then aux cs (i+1)
+              else aux cs (i+1)
+  in aux c 0;;

+ 90 - 0
MP/Mines2021.ml

@@ -0,0 +1,90 @@
+let numero_interieur z = let x = z/8 and y = z mod 8 in
+  (y <= 6 && x <= 6 && (abs(x-3) + abs(y-3)) <= 4 && x>=0 && y >= 0);;
+
+let rec intervalle a b = match a with
+  | a when a = b -> [a]
+  | a -> a::(intervalle (a+1) b);;
+
+let numeros_europeens = List.filter numero_interieur (intervalle 0 53);;
+
+type motif = int;;
+type ponctuel = motif;;
+
+let numero_vers_ponctuel (z:int) :ponctuel =
+  (1 lsl z);; 
+
+let rec numeros_vers_motifs (l:int list) :motif = match l with
+  | [] -> 0
+  | h::t -> (numero_vers_ponctuel h)lor(numeros_vers_motifs t);;
+
+let motif_europeen = numeros_vers_motifs numeros_europeens;;
+
+let est_ponctuel (m:motif) :bool = (m land (m-1)) = 0 && (m>0);;
+
+let inclus (m:motif) (p:ponctuel) :bool = (m land p) <> 0;;
+
+let valide (p:ponctuel):bool = inclus motif_europeen p;;
+
+let voisin_g (p:ponctuel) : ponctuel = let res = p lsl 1 in
+  if valide res then res else 0;;
+
+let voisin_d (p:ponctuel) : ponctuel = let res = p lsr 1 in
+  if valide res then res else 0;;
+
+let voisin_h (p:ponctuel) : ponctuel = let res = p lsl 8 in
+  if valide res then res else 0;;
+
+let voisin_b (p:ponctuel) : ponctuel = let res = p lsr 8 in
+  if valide res then res else 0;;
+
+let voisins p = [voisin_g p ;voisin_d p ;voisin_h p ;voisin_b p];;
+
+let retirer_ponctuel_dans_motif (m:motif) (p:ponctuel) :motif = m land (lnot p);;
+
+let existence_ponctuel_p_dans_motif (m:motif) (p:ponctuel) :bool = (m land p) =p;;
+
+(*let ajouter_ponctuel;;*)
+
+let coup_simple ((m,p) :motif*ponctuel) =
+  let coup_voisin = 
+    let case_suivante = voisins p in
+    let case_dapres = voisins case_suivante in
+    if (inclus m case_suivante) && not (inclus m case_dapres) && case_dapres <> 0 then
+      [m-p-case_suivante+case_dapres;case_dapres]
+    else
+      []
+    in List.flatten (List.map coup voisins)
+;;
+
+let coup_compose (c:motif*ponctuel) =
+
+  let rec aux l = 
+    if l = [] then []
+    else
+      let nv_couples = List.flatten (List.map coup_simple l) in
+      nv_couples@(aux nv_couples)
+  in aux [c]
+;;
+
+let mouvements (m:motif) : motif list =
+  let rec aux (p:ponctuel) =
+    if p = 1 lsl 53 then []
+    else (if inclus m p then coup_compose (m,p) else [])
+      @(aux (2*p))
+
+  in List.map fst (aux 4)
+;;
+let add_and_mem d (s:int) (m:motif) : bool =
+  let dedans = Hashtbl.mem d m in
+  if not dedans then Hashtbl.add d m s;
+  dedans
+;;
+
+let rec strate d (s:int) (l:motif list): motif list =
+  let nv_motifs = List.flatten (List.map mouvements l) in
+
+  if add_and_mem d s nv_motifs then
+    strate d (s+1) nv_motifs
+  else
+    []
+;;

+ 36 - 0
MP/abr.ml

@@ -0,0 +1,36 @@
+type 'a arbre = Vide | Noeud of 'a * 'a arbre * 'a arbre;;
+
+let rec max_arbre arbre1 = match arbre1 with
+| Vide -> 0
+| Noeud(r,g,d)-> max (max r (max_arbre g)) (max_arbre d)
+;;
+
+type 'a infini = Infplus| Infmoins | Valeur of 'a ;;
+
+(* let inferieurstrict x y = match scrutinee with
+| pattern -> pattern *)
+
+type abr = Vide | Noeud of int * abr * abr;;
+
+let rec test_abr a = match a with
+| Vide -> true
+| Noeud(r,g,d)-> ((r>=max_arbre g)&&(r<min_arbre)&&(test_abr g)&&(test_abr d))
+;;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 195 - 0
MP/abr2.ml

@@ -0,0 +1,195 @@
+(* A2324 - Arbres binaires de recherche *)
+
+(* d�finition du type arbre dont les �tiquettes sont des entiers,
+nous rappelons l'existence des deux constantes max_int et min_int de typ int 
+que vous pourrez assimiler respectivement � +infini et -infini *)
+type arbre = Vide | Noeud of int * arbre * arbre ;;
+
+(* exemple d'un arbre *)
+let a_ex = Noeud (150,
+             Noeud (60,
+               Noeud (40,
+                 Noeud(20,
+                   Vide,
+                   Noeud(30,Vide,Vide)
+                   ),
+                 Noeud(50,Vide,Vide)
+                 ),
+               Noeud (70,
+                 Vide,
+                 Noeud(130,
+                   Noeud(90,Vide,Vide),
+                   Vide
+                 )
+               )
+            ),
+             Noeud (190,
+               Noeud (170,
+                 Vide,
+                 Noeud (180,Vide,Vide)
+               ),
+               Noeud(200,Vide,Vide)
+               )
+             )
+;;
+(* Q1 : repr�senter proprement cet arbres sur votre copie, 
+est-ce un ABR ? aucune justification n'est demand�e *)
+
+(* recherche de la valeur maximale, de la valeur minimale des �tiquettes d'un arbre quelconque *)
+(*Comme a est un arbre, on peut comparer la racine du noeud courant avec le maximum du fils droit et le maximum du fils gauche*)
+let rec max_arbre (a:arbre) : int = match a with
+  | Vide -> min_int
+  | Noeud (r,fg,fd) -> max (max r (max_arbre fg)) (max_arbre fd) ;;
+  
+max_arbre a_ex ;;
+(*De même, on prend le minimum du noeud courant, et on lance les appels récursifs*)
+let rec min_arbre (a:arbre) : int = match a with
+  | Vide -> max_int
+  | Noeud (r,fg,fd) -> min (min r (min_arbre fg)) (min_arbre fd) ;;
+  
+min_arbre a_ex ;;
+
+(* Q2 : �crire une fonction qui teste si un arbre est un ABR *)
+(*Pour tester si un arbre est un abr, il suffit de vérifier que la racine est plus grande que tous ses fils de gauche, plus petite que tous ses fils de droite, et que ces 2 fils sont bien des abr*)
+let rec test_abr (a:arbre) : bool = match a with
+| Vide -> true
+| Noeud(r,g,d)-> (max_arbre g < r) && (r < min_arbre d) && (test_abr g) && (test_abr d)
+;;
+
+test_abr a_ex ;;
+
+(* Q3 : �crire une fonction qui effectue le parcours en profondeur en mode infixe d'un arbre *)
+(*Comme le parcours en profondeur, mode infixe repose sur la deuxième fois que l'on voit un objet, on le met en seconde position, et on effectue le parcours sur les 2 sous-arbres*)
+
+let rec parcours_pro_inf (a:arbre) :(int list) = match a with
+| Vide -> []
+| Noeud(r,g,d) -> (parcours_pro_inf g) @ [r] @ (parcours_pro_inf d)
+;;
+
+parcours_pro_inf a_ex ;;
+
+(* Q4 : �crire une fonction qui recherche une valeur dans les �tiquettes d'un ABR
+en profitant de la,structure d'ABR *)
+(*On profite de la structure d'abr, en ne recherchant que dans le sous-fil correspondant à la valeur de x<r, ce qui réduit drastiquement la complexité*)
+let rec recherche_abr (a:arbre) (x:int) : bool = match a with
+| Vide -> false
+| Noeud(r,g,d) -> if r = x then true
+                  else if r > x then recherche_abr g x
+                  else recherche_abr d x
+;;
+
+recherche_abr a_ex 91 ;;
+
+(* Q5 : �crire une fonction qui recherche l'�tiquette de valeur maximale dans un ABR en complexit� logarithmique *)
+(*On profite de la structure d'abr pour chercher le maximum, qui se trouvera forcèment dans le sous-arbre de droite. De plus, il se situe sur les feuilles, donc ces 2 sous-fils sont Vide*)
+(*Pour les 2 programmes, on prend Vide->0, ce choix est dû au fait que notre arbre est uniquement composé d'entiers positifs*)
+let rec cle_max (a:arbre) : int = match a with
+| Vide -> 0
+| Noeud(r,g,d) -> if d = Vide then r
+                  else cle_max d
+;;
+cle_max a_ex;;
+(* Q6 : �crire une fonction qui recherche l'�tiquette de valeur maximale dans un ABR en complexit� logarithmique *)
+(*De même, sauf que cette fois, on regarde le minimum dans le sous-arbre de gauche*)
+let rec cle_min (a:arbre) : int = match a with
+| Vide -> 0
+| Noeud(r,g,d) -> if g = Vide then r
+                  else cle_min g  
+;;
+
+cle_min a_ex ;;
+
+(* Q7 : �crire une fonction qui renvoie la plus grande valeur e parmi les �tiquettes de l'arbre
+strictement inf�rieure � une valeur donn�e *)
+(*On utilise la structure d'abr, si r<c, alors on recher le maximum entre la racine et la clé prédecesseur dans le sous-fil droit. Sinon, si r>=c, alors on recherche un predeccesseur dans le sous-arbre gauche. Quand on arrive sur les feuilles, on les compare avec -Inf*)
+let rec cle_predecesseur (a:arbre) (c:int) : int = match a with
+| Vide -> min_int
+| Noeud(r,g,d) -> if r < c then max r (cle_predecesseur d c)
+                  else cle_predecesseur g c
+;;
+
+cle_predecesseur a_ex 141 ;;
+
+(* Q7 : �crire une fonction qui renvoie la plus petite valeur e parmi les �tiquettes de l'arbre
+strictement sup�rieure � une valeur donn�e *)
+(*De même, sauf que cette fois on recherche un minimum, donc on compare par rapport à +Inf*)
+let rec cle_successeur (a:arbre) (c:int) : int = match a with
+| Vide -> max_int
+| Noeud(r,g,d) -> if r > c then min r (cle_successeur g c)
+                  else cle_successeur d c
+;;
+cle_successeur a_ex 71;;
+(* Q8 : �crire une fonction qui ins�re un �l�ment dans un ABR en conservant la structure d'ABR,
+insertion an niveau des feuilles de l'arbre *)
+(*On compare la feuille à insérer avec le noeud courant: si le noeud courant est plus grand que l'entier à insérer, alors on insére récursivement sur le sous-fil gauche*)
+(*Sinon, on insère récursivement dans le sous-fil droit, pour conserver le caractère d'abr*)
+let rec insertion_feuilles (a:arbre) (c:int) : arbre = match a with
+| Vide -> Noeud(c,Vide,Vide)
+| Noeud(r,g,d) -> if r > c then Noeud(r,insertion_feuilles g c,d)
+                  else Noeud(r,g,insertion_feuilles d c)
+;;
+
+insertion_feuilles a_ex 80 ;;
+
+(* Q9 : �crire une fonction qui ins�re un �l�ment dans un ABR en conservant la structure d'ABR,
+insertion an niveau de la racine de l'arbre *)
+(*on cherche à séparer en 2, par rapport à c. Ainsi, si le noeud courant est plus grand que c, alors on sépare le sous-fil gauche*)
+(*Si on sépare l'arbre vide, alors on renvoit le couple de 2 arbres vides, qui est une partition de l'arbre vide*)
+(*Puis on crée récursivement une partition de l'arbre, par rapport à c*)
+(*le couple crée est composée, d'une part de la partie inférieure à c, d'autre part de la partie supérieure à c*)
+let rec partition (a:arbre) (c:int) : (arbre*arbre) = match a with
+| Vide -> (Vide,Vide)
+| Noeud(r,g,d) -> if r > c then let (g1,d1) = partition g c in (g1, Noeud(r,d1,d))
+    else let (g1,d1) = partition d c in (Noeud(r,g,g1),d1) 
+;;
+partition a_ex 80 ;;
+(*Comme on a la partition, on crée la partiition de a par rapport à c, puis on crée un arbre avec c comme racine, partiition gauche à gauche et partition droite à droite: Noeud(c,g1,d1)*)
+let insertion_racine (a:arbre) (c:int) : arbre = match a with
+| Vide -> Noeud(c,Vide,Vide)
+| Noeud(r,g,d) -> let (g1,d1) = partition a c in Noeud(c,g1,d1)
+;;
+
+insertion_racine a_ex 80 ;;
+
+(* Q10 a : �crire une fonction qui renvoie la valeur minimale des �tiquettes de l'arbre
+et l'arbre priv� d'un sommet ayant une �tiquette de cette valeur minimale *)
+(*On recherche le minimum dans un arbre, tout en la supprimant*)
+(*Pour cela, on vérifie si g n'est pas Vide, car sinon le minimum se trouve en le noeud courant*)
+(*Sinon, on supprime récursivement le minimum dans le sous-fil gauche*)
+(*On utilise min_int afin de trouver le minimum et d'avoir un élément de comparaison qui sera bien plus petit que tout élément de l'arbre, que nous supposons être des entiers naturels*)
+let rec supprime_cle_min (a:arbre) : (int*arbre) = match a with
+| Vide -> (min_int,Vide)
+| Noeud(r,g,d) -> if g = Vide then (r,d)
+                  else let (r1,g1) = supprime_cle_min g in (r1,Noeud(r,g1,d))
+;;
+supprime_cle_min a_ex ;;
+(* Q10 b : �crire une fonction qui supprime un �l�ment dans un ABR en conservant le structure d'ABR 
+ATTENTION : faute de frappe sur le cours, avec valeur minimale, �changer gauche et droit ! *)
+(* pr�condition : une �tiquette de l'arbre est �gale � c *)
+(*On cherche à supprimer un élément dans un abr, en conservant la structure d'abr*)
+
+(*Si la racine r est égale à la clé c, cela signifie que le nœud à supprimer est trouvé.
+Il appelle la fonction supprime_cle_min sur le sous-arbre droit d pour trouver le nœud avec la clé minimale 
+dans le sous-arbre droit, le supprime et remplace la racine par ce nœud. 
+La fonction supprime_cle_min devrait renvoyer une paire (r1,d1) où r1 est la clé minimale 
+et d1 est le sous-arbre droit après avoir supprimé le nœud avec la clé minimale.*)
+
+(*Sinon, le noeud courant est plus grand que la valeur à enlever, alors on supprime récursivement dans le sous-fil gauche*)
+(*Sinon, on fait la même chose dans le sous-fil droit*)
+let rec supprime_cle (a:arbre) (c:int) : arbre = match a with
+| Vide -> Vide
+| Noeud(r,g,d) -> if r = c then let (r1,d1) = supprime_cle_min d in Noeud(r1,g,d1)
+                  else if r > c then Noeud(r,supprime_cle g c,d)
+                  else Noeud(r,g,supprime_cle d c)
+;;
+supprime_cle a_ex 150;;
+
+(*On effectue un parcours en profondeur de l'arbre, en rajoutant la condition que si le sous - arbre gauche est vide, alors on ajoute à droite la feuille*)
+let rec parcours_pro_inf_bis (a:arbre) :(int list) = match a with
+| Vide -> []
+| Noeud(r,Vide,d)-> (parcours_pro_inf_bis d) @ [r]
+| Noeud(r,g,d) -> (parcours_pro_inf_bis g) @ [r] @ (parcours_pro_inf_bis d)
+;;
+
+parcours_pro_inf_bis a_ex;;
+

+ 226 - 0
MP/concours/arbres.ml

@@ -0,0 +1,226 @@
+type 'a arbre = Vide | Noeud of 'a * 'a arbre * 'a arbre;;
+
+let ex1 = Noeud(1, Noeud(2, Noeud(4, Vide, Vide), Noeud(5, Vide, Vide)), Noeud(3, Noeud(6, Vide, Vide), Noeud(7, Vide, Vide)));;
+
+let rec nbr_sommets a = match a with
+| Vide -> 0
+| Noeud(_, g, d) -> 1 + nbr_sommets g + nbr_sommets d;;
+
+let rec hauteur a = match a with
+| Vide -> 0
+| Noeud(_, g, d) -> 1 + max (hauteur g) (hauteur d);;
+
+let rec somme a = match a with
+| Vide -> 0
+| Noeud(x, g, d) -> x + somme g + somme d;;
+
+let rec miroir a = match a with
+| Vide -> Vide
+| Noeud(x, g, d) -> Noeud(x, miroir d, miroir g);;
+
+let rec est_miroir a1 a2 = match a1, a2 with
+| Vide, Vide -> true
+| Vide, Noeud(_, _, _) -> false
+| Noeud(_, _, _), Vide -> false
+| Noeud(_, g1, d1), Noeud(_, g2, d2) -> est_miroir g1 d2 && est_miroir d1 g2;;
+
+let rec est_complet a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, Vide) -> false
+| Noeud(_, Vide, d) -> false
+| Noeud(_, g, d) -> est_complet g && est_complet d;;
+
+let rec est_parfait a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, d) -> est_parfait g && est_parfait d && hauteur g = hauteur d;;
+
+let rec est_arbre_binaire a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, Vide) -> est_arbre_binaire g
+| Noeud(_, Vide, d) -> est_arbre_binaire d
+| Noeud(_, g, d) -> est_arbre_binaire g && est_arbre_binaire d;;
+
+let rec est_arbre_binaire_complet a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, Vide) -> false
+| Noeud(_, Vide, d) -> false
+| Noeud(_, g, d) -> est_arbre_binaire_complet g && est_arbre_binaire_complet d && hauteur g = hauteur d;;
+
+let rec est_arbre_binaire_parfait a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, d) -> est_arbre_binaire_parfait g && est_arbre_binaire_parfait d && hauteur g = hauteur d;;
+
+let rec est_arbre_binaire_miroir a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, Vide) -> est_arbre_binaire_miroir g
+| Noeud(_, Vide, d) -> est_arbre_binaire_miroir d
+| Noeud(_, g, d) -> est_arbre_binaire_miroir g && est_arbre_binaire_miroir d;;
+
+let rec est_arbre_binaire_complet_miroir a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, Vide) -> false
+| Noeud(_, Vide, d) -> false
+| Noeud(_, g, d) -> est_arbre_binaire_complet_miroir g && est_arbre_binaire_complet_miroir d && hauteur g = hauteur d;;
+
+let rec est_arbre_binaire_parfait_miroir a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, d) -> est_arbre_binaire_parfait_miroir g && est_arbre_binaire_parfait_miroir d && hauteur g = hauteur d;;
+
+let rec noeuds a = match a with
+| Vide -> []
+| Noeud(x, g, d) -> x::(noeuds g)@(noeuds d);;
+
+let rec nbr_noeuds a = match a with
+| Vide -> 0
+| Noeud(_,Vide,Vide) -> 0
+| Noeud(_,g,d) -> 1 + nbr_noeuds g + nbr_noeuds d;;
+
+let rec nbr_feuilles a = match a with
+| Vide -> 0
+| Noeud(_, Vide, Vide) -> 1
+| Noeud(_, g, d) -> nbr_feuilles g + nbr_feuilles d;;
+
+let rec est_feuille a = match a with
+| Vide -> false
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, g, d) -> false;;
+
+let rec feuilles a = match a with
+| Vide -> []
+| Noeud(x, Vide, Vide) -> [x]
+| Noeud(_, g, d) -> (feuilles g)@(feuilles d);;
+
+let rec maximum a = match a with
+| Vide -> failwith "arbre vide"
+| Noeud(x, Vide, Vide) -> x
+| Noeud(x, g, d) -> max x (max (maximum g) (maximum d));;
+
+let rec minimum a = match a with
+| Vide -> failwith "arbre vide"
+| Noeud(x, Vide, Vide) -> x
+| Noeud(x, g, d) -> min x (min (minimum g) (minimum d));;
+
+let rec entier a = match a with
+| Vide -> true
+| Noeud(_, Vide, Vide) -> true
+| Noeud(_, Vide, _) -> false
+| Noeud(_, _, Vide) -> false
+| Noeud(x, g, d) -> entier g && entier d;;
+
+let rec prefixe a = match a with
+| Vide -> []
+| Noeud(r,Vide,Vide)-> [r]
+| Noeud(x, g, d) -> (x::prefixe g)@(prefixe d);;
+
+let rec infixe a = match a with
+| Vide -> []
+| Noeud(r,Vide,Vide)-> [r]
+| Noeud(x, g, d) -> (infixe g)@(x::infixe d);;
+
+let rec postfixe a = match a with
+| Vide -> []
+| Noeud(r,Vide,Vide)-> [r]
+| Noeud(x, g, d) -> (postfixe g)@(postfixe d)@[x];;
+
+let rec liste_racines l = match l with
+| [] -> []
+| (Noeud(x, _, _)::q) -> x::(liste_racines q);;
+
+let rec liste_fils l = match l with
+| [] -> []
+| (Noeud(_, g, d)::q) -> (g::d::(liste_fils q));;
+
+
+let rec parcours_largeur a =
+  let rec aux l = match l with
+  | [] -> []
+  | _ -> (liste_racines l)@(aux (liste_fils l)) in
+  aux [a];;
+
+type arbre_bin = Vide | Noeud of int * arbre_bin * arbre_bin;;
+
+type compa = Inf | Sup | Egal;;
+
+let compare_int x y = if x < y then Inf else if x > y then Sup else Egal;;
+
+let rec recherche (a:arbre_bin) f (x:int) = match a with
+| Vide -> false
+| Noeud(y, g, d) -> match f x y with
+  | Egal -> true
+  | Inf -> recherche g f x
+  | Sup -> recherche d f x;;
+
+let rec min_gauche_max_droit a = match a with
+| Vide -> failwith "arbre vide"
+| Noeud(e,Vide,Vide) -> (e,e)
+| Noeud(e,ag,Vide)-> let (min, max) = min_gauche_max_droit ag in (min, e)
+| Noeud(e,Vide,ad)-> let (min, max) = min_gauche_max_droit ad in (e, max)
+| Noeud(e,ag,ad)-> let (min, max) = min_gauche_max_droit ag in (min, max);;
+
+let rec verif_encadre a f x y= match a with
+| Vide -> true
+| Noeud(e,ag,ad) -> not(f e x = Inf) && not(f e y = Sup) && verif_encadre ag f x e && verif_encadre ad f e y;;
+
+let verif_arbre_recherche a f = let (min, max) = min_gauche_max_droit a in verif_encadre a f min max;;
+
+let rec verif_tri l f = match l with
+| [] -> true
+| [x] -> true
+| t::t1::q -> not(f t t1 = Sup) && verif_tri (t1::q) f;;
+
+let rec infixe2 a = match a with
+| Vide -> []
+| Noeud(r,Vide,Vide)-> [r]
+| Noeud(x, g, d) -> (infixe2 g)@(x::infixe2 d);;
+
+let verif_arbre_recherche2 a f = verif_tri (infixe2 a) f;;
+
+let rec insere_feuille a f x = match a with
+| Vide -> Noeud(x, Vide, Vide)
+| Noeud(e, g, d) -> match f x e with
+  | Egal -> a
+  | Inf -> Noeud(e, insere_feuille g f x, d)
+  | Sup -> Noeud(e, g, insere_feuille d f x);;
+
+let rec decoupe (a:arbre_bin) f (x:int) : arbre_bin * arbre_bin= match a with
+| Vide -> (Vide, Vide)
+| Noeud(e, g, d) -> match f x e with
+  | Egal -> (g, d)
+  | Inf -> let (g1, d1) = decoupe g f x in (g1, Noeud(e, d1, d))
+  | Sup -> let (g1, d1) = decoupe d f x in (Noeud(e, g, g1), d1);;
+
+let insere_racine a f x = let (g, d) = decoupe a f x in Noeud(x, g, d);;
+
+let rec construction_feuille l f = match l with
+| [] -> Vide
+| t::q -> insere_feuille (construction_feuille q f) f t;;
+
+let rec construction_racine l f = match l with
+| [] -> Vide
+| t::q -> insere_racine (construction_racine q f) f t;;
+
+let rec rotation_gauche a = match a with
+| Vide -> Vide
+| Noeud(x, Vide, Vide) -> Noeud(x, Vide, Vide)
+| Noeud(x, Noeud(y, g, d), Vide) -> Noeud(y, g, Noeud(x, d, Vide))
+| Noeud(x, g, d) -> Noeud(x, rotation_gauche g, d);;
+
+let rec rotation_droite a = match a with
+| Vide -> Vide
+| Noeud(x, Vide, Vide) -> Noeud(x, Vide, Vide)
+| Noeud(x, Vide, Noeud(y, g, d)) -> Noeud(y, Noeud(x, Vide, g), d)
+| Noeud(x, g, d) -> Noeud(x, g, rotation_droite d);;
+
+let rec fusionne a1 a2 = match a1, a2 with
+| Vide, Vide -> Vide
+| Vide, Noeud(x, g, d) -> Noeud(x, g, d)
+| Noeud(x, g, d), Vide -> Noeud(x, g, d)
+| Noeud(x, g, d), Noeud(y, g1, d1) -> let (min, max) = min_gauche_max_droit a2 in Noeud(min, g, fusionne d a2);;

+ 179 - 0
MP/concours/tri.ml

@@ -0,0 +1,179 @@
+(*Tri par insertion sur des listes*)
+let rec insere x l = match l with
+| [] -> [x]
+| t::_ when t>x -> x::l
+| t::q -> t::(insere x q)
+;;
+
+let rec tri_insertion l = match l with
+| [] -> []
+| t::q -> insere t (tri_insertion q)
+;;
+
+(*Tri par insertion sur des tableaux*)
+let insere_t i t = let k = ref (i-1) and aux = t.(i) in
+  while (!k >= 0) && (t.(!k)> aux) do
+    t.(!k+1)<- t.(!k);
+    k:= !k +1
+  done;
+  t.(!k+1) <- aux
+;;
+
+let tri_insertion_t t = let n = Array.length t in
+  for i = 1 to n do
+  insere_t i t
+  done;
+  t
+;;
+
+(*Tri par selection sur des tableaux*)
+let rec echange i j a = let aux = a.(i) in
+ a.(i)<- a.(j);
+ a.(j)<-aux
+;;
+let minimum t i = let m = ref i in
+  for j= i+1 to Array.length t do
+    if t.(j)< !m then m:= j
+    done;
+    !m
+;;
+let tri_selection t = let n = Array.length t in
+  for i = 0 to n-2 do
+    echange (minimum t i) i t
+  done;
+  t
+;;
+(*Tri par selection sur des listes*)
+let rec minimum_et_reste l = match l with
+| [] -> failwith "Pas d'élément dans la liste"
+| [a] -> a,[]
+| t::q -> let (m,r) = minimum_et_reste q in
+  if m<t then (m, t::r)
+  else (t,q)
+;;
+
+let rec tri_selection_l l = match l with
+| [] -> []
+| _ -> let (m,r) = minimum_et_reste l in
+  m::(tri_selection_l r)
+;;
+(*Tri à bulles sur des tableaux*)
+let rec une_etape t i = let n = Array.length t and b = ref false in
+  for k = n-1 downto i+1 do
+    if (t.(k)< t.(k-1)) then
+      begin
+        echange k (k-1) t;
+        b:= true
+      end
+    done;
+    !b
+;;
+let tri_bulles t = let i = ref 0 in
+  while (une_etape t !i) do
+    i := !i + 1
+  done;
+  t
+;;
+(*Tri à bulles sur des listes*)
+let rec une_etape_l l = match l with
+| [] -> false,l
+| t::q -> let b,t1::q1 = une_etape_l q in
+  if (t<= t1) then b, t::t1::q
+  else true,t1::t::q
+;;
+
+let rec tri_bulles_l l = match l with
+| [] -> []
+| _ -> let b,t::q = une_etape_l l in
+  if b then t::(tri_bulles_l q)
+  else l
+;;
+(*Tri fusion pour des listes*)
+let rec partition l = match l with
+| [] -> ([],[])
+| [x] -> ([x],[])
+| t1::t2::q -> let q1,q2 = partition q in (t1::q1,t2::q2)
+;;
+
+let rec fusion l1 l2 = match (l1,l2) with
+| [],[] -> []
+| [],l2 -> l2
+| l1,[] -> l1
+| t1::q1,t2::q2 -> if t1 <= t2 then t1::(fusion q1 l2)
+  else t2::(fusion l1 q2)
+;;
+let rec tri_fusion l = match l with
+| [] -> []
+| [x] -> [x]
+| _ -> let l1,l2 = partition l in
+  fusion (tri_fusion l1) (tri_fusion l2)
+;;
+(*Tri fusion pour les tableaux*)
+let fusion_t t l m u =
+  let aux = Array.make (u-l + 1) t.(0) and i = ref l and j = ref (m+1) and k = ref 0 in
+  while (!i<= m) && (!j <= u) do
+    if (t.(!i)<= t.(!j)) then
+      begin
+        aux.(!k) <- t.(!i);
+        i:= !i + 1
+      end
+    else
+      begin
+        aux.(!k) <- t.(!j);
+        j := !j +1
+      end;
+      k:= !k + 1
+    done;
+    while (!i <= m) do
+      aux.(!k) <- t.(!i);
+      i:= !i +1;
+      k:= !k + 1
+    done;
+    while (!j <= u) do
+      aux.(!k) <- t.(!j);
+      j:= !j + 1;
+      k := !k +1
+    done;
+    for x=0 to (!k-1) do
+      t.(l+x) <- aux.(x)
+    done
+;;
+
+let tri_fusion_t t =
+  let rec tri_fuion_aux t l u =
+    if (l<u) then
+      begin
+        let m = (l+u)/2 in
+          tri_fuion_aux t l m;
+          tri_fuion_aux t (m+1) u;
+          fusion_t t l m u;
+      end;
+    in tri_fuion_aux t 0 (Array.length t -1 )
+;;
+
+(*Tri rapide pour les tableaux*)
+
+let partition_rapide t d f =
+  let p = t.(d) and i = ref d in
+    for j = d+1 to f do
+      if t.(j) <= p then
+        begin
+          i := !i + 1;
+          echange !i j t
+        end
+      done;
+      echange d !i t;
+      !i
+;;
+
+let tri_rapide t =
+  let rec aux t d f =
+    if f > d then
+      begin
+        let m = partition_rapide t d f in
+          aux t d (m-1);
+          aux t (m+1) f
+      end
+    in
+    aux t 0 (Array.length t -1)
+;;

+ 99 - 0
MP/kmp.ml

@@ -0,0 +1,99 @@
+(*Vérifie que x appartient au mot t, il faut trouver l'entièreté de x*)
+let recherche_iterative (t:string) (x:string) : bool = let i = ref 0 and j = ref 0 in
+  while !i < String.length t && !j < String.length x do
+    if t.[!i] = x.[!j] then 
+      begin
+      j := !j + 1;
+      i := !i + 1
+      end
+    else
+      begin
+      j := 0; 
+      i := !i + 1
+    end
+  done;
+  !j = String.length x
+;;
+
+(*Trouver le bord strict d'un mot*)
+
+let border_length (t:string) : int = 
+  let i = ref 1 and j = ref 0 in
+    while !i < String.length t && t.[!i] = t.[!j] do
+      i := !i + 1;
+      j := !j + 1
+    done;
+    !j
+;;
+let rec est_prefixe_recursif (t:char list) (x:char list) (copy_x: char list) :bool = match (t,x) with
+| [],[] -> true
+| [],_ -> false
+| _,[] -> true
+| t1::q1,t2::q2 -> if t1 = t2 then est_prefixe_recursif q1 q2 copy_x else est_prefixe_recursif q1 copy_x copy_x
+;;
+
+(*monpapimamamanmonpapamamaman*)
+(*Recherche d'un mot en récursif, en utilisant est_prefixe_recursif*)
+
+(*let rec recherche_recursif t x = match t with
+| [] -> false
+| t1::q1 -> if est_prefixe_recursif t1 x then true else recherche_recursif q1 x;;
+*)
+
+(*Renvoie le plus grand entier j tel que toute les lettres de entre vk et v(k+j-1) soient égales à wl ... w(l+j-1)*)
+let compare_sub_strings (v:string) (k:int) (w:string) (l:int) (s:int) : int =
+  let j = ref 0 in
+    while !j < s && !j < String.length v -k + (!j) && !j < String.length w -l + (!j) && v.[k + !j] = w.[l + !j] do
+      j := !j + 1
+    done;
+    !j
+;;
+
+compare_sub_strings "monpapimamamanmonpapamamaman" 0 "monpsdnv" 0 2;;
+
+let test_egalite_sub_strings (v:string) (k:int) (w:string) (l:int) (s:int) : bool =
+  s = compare_sub_strings v k w l s
+;;
+
+(*En testant les préfixes stricts du mot w un par un*)
+(*Calcule la longueur du bord d'un mot w*)
+(*Un bord est un préfixe et un suffixe*)
+let border_length (w:string) : int =
+  let n = String.length w in
+    let k = ref (n-1) in
+      while !k > 0 && not (test_egalite_sub_strings w 0 w (n - !k) !k) do
+        k := !k - 1
+      done;
+      !k
+;;
+
+border_length "maacadamaa";;
+
+let borders_naif w : int array = 
+  let n = String.length w in
+    let b = Array.make (n+1) (-1) in
+      for i = 1 to n do
+        b.(i) <- border_length (String.sub w 0 i)
+      done;
+      b
+;;
+
+borders_naif "ababaa";;
+
+let kmp (t:string) (x:string) : bool =
+  let deb = ref 0 and i = ref 0 and j = ref 0 in
+    while !i < String.length t && !j < String.length x do
+      if t.[!i] = x.[!j] then
+        begin
+        i := !i + 1;
+        j := !j + 1
+        end
+      else
+        begin
+        j := 0;
+        deb := !i + 1;
+        i := !i + 1
+        end
+    done;
+    !j = String.length x
+;;

+ 31 - 0
MP/test.ml

@@ -0,0 +1,31 @@
+type 'a poids = Poids of 'a | Infini;;
+
+let rec insere i x l =
+  match l with
+  | [] -> [i]
+  | t::q -> if x > t then i :: l else t :: (insere i x q)
+;;
+
+let liste_triee_arrete w =
+  let l = ref [] and n = List.length w in
+  for i = 0 to n - 2 do
+    for j = i + 1 to (n - 1) do
+      match (List.nth w i).(j) with
+      | Poids(p) -> l := insere (i, j) p !l
+      | Infini -> ()
+    done;
+  done;
+  !l
+;;
+
+let g = [
+  [Infini; Poids(9); Infini; Poids(5); Infini; Infini; Infini];
+  [Poids(7); Infini; Poids(8); Poids(9); Poids(7); Infini; Infini];
+  [Infini; Poids(8); Infini; Infini; Poids(5); Infini; Infini];
+  [Poids(5); Poids(9); Infini; Infini; Poids(15); Poids(6); Infini];
+  [Infini; Poids(7); Poids(5); Poids(15); Infini; Poids(8); Poids(9)];
+  [Infini; Infini; Infini; Poids(6); Poids(8); Infini; Poids(11)];
+  [Infini; Infini; Infini; Infini; Poids(9); Poids(11); Infini];
+];;
+
+let aretes = liste_triee_arrete g;;

+ 46 - 0
TP5/tp5.ml

@@ -0,0 +1,46 @@
+type formule =
+| Var of string
+| Neg of formule
+| Et of formule * formule
+| Ou of formule * formule
+;;
+
+let ex = Et(Var "p", Neg(Ou(Var "q", Var "r")));;
+
+
+let rec string_of_formule formule = match formule with
+| Var (s) -> "s"
+| Neg (f) -> "neg" ^ (string_of_formule f)
+| Et (f1,f2) -> (string_of_formule f1) ^ "et" ^ (string_of_formule f2)
+| Ou (f1,f2) -> (string_of_formule f1) ^ "ou" ^ (string_of_formule f2)
+;;
+
+let rec reunion l1 l2 = match (l1,l2) with
+| ([],[]) -> []
+| l1,[] -> l1
+| ([],l2) -> l2
+| t1::q1,l2 -> if not (List.mem t1 l2) then t1::(reunion q1 l2)
+else (reunion q1 l2)
+;;
+
+let rec list_of_vars formule acc = match formule with
+| Var x -> reunion [x] acc
+| Neg (f) -> list_of_vars f acc 
+| Et (f1,f2) -> reunion (list_of_vars f1 acc) (list_of_vars f2 acc) 
+| Ou (f1,f2) -> reunion (list_of_vars f1 acc) (list_of_vars f2 acc) 
+;;
+
+let rec eval_formule formule machin = match formule with
+| Var x -> List.assoc x machin == true
+| Neg (f) -> eval_formule f machin == false
+| Et (f1,f2) -> (eval_formule f1 machin) && (eval_formule f2 machin)
+| Ou (f1,f2) -> (eval_formule f1 machin) || (eval_formule f2 machin)
+;;
+let ex2 = Et(Var "p", Neg(Ou(Var "q", Var "r")));;
+let ex3 = [("p",true); ("q",false); ("r", true)];;
+
+let add_to_all a truc = List.map (function l0 ->a::l0) truc;;
+let rec affectation_vars sl = match sl with
+| [] -> []
+| t::q -> (affectation_vars q)@[(add_to_all t q)@(add_to_all (t,false))]
+;;

+ 17 - 0
test2/huffmann.ml

@@ -0,0 +1,17 @@
+type suite = char list;;
+
+type code = bool list;;
+
+type cle = (char * code) list;;
+
+let coder (s:suite) (c:cle)=
+  let rec code_of_char t cl = match cl with
+    | [] -> failwith "Erreur dans coder"
+    | (x,l)::r -> if x=t then l
+
+    else code_of_char t r
+
+    and coder_aux ss = match ss with
+    |  [] -> []
+    | t::q -> (code_of_char t c)@(coder_aux q)
+in coder_aux s ;;