Pārlūkot izejas kodu

Initial Commit ^^

Clemsim 2 gadi atpakaļ
revīzija
7849c8db24

+ 137 - 0
TP1/1.ml

@@ -0,0 +1,137 @@
+let rec longueur l = match l with
+| [] -> 0
+| t::q -> 1 + longueur q;;
+
+let rec appartient x l = match l with
+| [] -> false
+| t::q -> if t = x then
+  true
+else
+  appartient x q;;
+ 
+let rec occurence x l = match l with
+| [] -> 0
+| t::q -> if t = x then
+    1+ occurence x q
+else
+  occurence x q;;
+
+let rec dernier l = match l with
+| [a] -> a
+| t::q -> dernier q;;
+
+let rec ajout_fin x l = match l with
+| [] -> [x]
+| t::q -> t::ajout_fin x q;;
+
+let rec ieme i l = let x::xs=l in
+  if i = 0 then x else ieme (i-1) xs
+
+let rec supprime i l = let t::q =l in
+match i with
+| 1 -> List.tl l
+| _ -> t::(supprime (i-1) q);;
+
+
+let rec supprimetout x l = match l with
+| [] -> []
+| t::q -> 
+  if t=x then
+    supprimetout x q
+  else
+    t::(supprimetout x q);;
+
+let rec insere x i l= let t::q=l in
+match i with
+| 1 -> x::l 
+| _ -> t::(insere x (i-1) q);;
+
+let rec concatene l1 l2 =
+match l2 with
+| [] -> l1
+| t::q -> t::(concatene l1 q);;
+
+let rec concatene_inverse l1 l2 =
+  match l1 with
+  | [] -> List.rev l2
+  | x :: xs -> concatene_inverse xs (x :: l2);;
+let rec mirroir l =
+  match l with
+  | [] -> []
+  | x :: xs -> mirroir xs @ [x];;
+
+let rec addition l1 l2 =
+  match (l1, l2) with
+  | ([], _) -> l2
+  | (_, []) -> l1
+  | (x :: xs, y :: ys) -> (x + y) :: addition xs ys
+;;
+let rec fusion l1 l2 =
+  match (l1, l2) with
+  | ([], _) -> l2
+  | (_, []) -> l1
+  | (x :: xs, y :: ys) ->
+      if x <= y then
+        x :: fusion xs l2
+      else
+        y :: fusion l1 ys;;
+
+
+
+let rec somme l = match l with
+| [] -> 0
+| t::q -> t+somme q;;
+
+let rec maximum l =
+  match l with
+  | [] -> failwith "empty list"
+  | [x] -> x
+  | x :: xs ->
+      let max_tail = maximum xs in
+      if x > max_tail then x else max_tail
+
+
+let rec second_max l =
+  match l with
+  | [] | [_] -> failwith "not enough elements"
+  | [x; y] -> if x > y then y else x
+  | x :: xs ->
+      let (max_tail, second_max_tail) = (maximum xs, second_max xs) in
+      if x > max_tail then
+        if max_tail > second_max_tail then max_tail else second_max_tail
+      else
+        if x > second_max_tail then x else second_max_tail
+
+let rec evaluation p x =
+  match p with
+  | [] -> 0.0
+  | a :: [] -> a
+  | a :: b :: xs ->
+      let q = b +. x *. evaluation xs x in
+      evaluation (q :: xs) x +. a
+
+
+let rec binomial n p = match (n,p) with
+| (n,0) -> 1
+| (n,p) when p=n -> 1
+| _ -> binomial(n-1) p + binomial (n-1) (p-1);;
+
+let rec ligne_suivante l =
+  match l with
+  | [] -> [1]
+  | x :: xs ->
+      let rec aux acc prev = 
+        match prev with
+        | [] -> List.rev (1 :: acc)
+        | y :: ys -> aux ((x + y) :: acc) ys
+      in aux [] l;;
+
+let rec pascal n =
+  match n with
+  | 0 -> []
+  | 1 -> [[1]]
+  | _ ->
+      let prev = pascal (n - 1) in
+      let last = List.hd (List.rev prev) in
+      let next = ligne_suivante last in
+      prev @ [next]

+ 70 - 0
TP2/tp2.ml

@@ -0,0 +1,70 @@
+let insere i t = 
+  let j = ref i in
+    while !j> 0 && t.(!j)<t.(!j-1) do
+      let aux = t.(!j) in
+        t.(!j)<- t.(!j-1);
+        t.(!j-1)<-aux;
+        j := !j - 1
+    done;
+;;
+
+let tri_insertion t =
+  let n = Array.length t in
+    for i = 1 to n-1 do
+    insere i t
+    done;
+    t
+;;
+
+let rec minimum_reste l = match l with
+| [x] -> x, []
+| t1::q -> let (m,r) = minimum_reste q in
+  if t1<m then (t1,m::r)
+  else (m,t1::r);;
+
+let rec tri_selection l = match l with
+| [x] -> [x]
+| _ -> let (aux1,aux2) = minimum_reste(l) in
+  aux1::tri_selection aux2
+;;
+
+let rec une_etape l = match l with
+| [x] -> false,[x]
+| t::q -> let b, t1::q1 = une_etape q in
+  if t1>t then b, t::t1::q1
+
+  else true, t1::t::q1;;
+
+let rec tri_bulles l = match l with 
+| [] -> []
+| _ -> let b,t::q = une_etape l in
+  if b then t::(tri_bulles q)
+  else l
+;;
+
+
+let echange t i j = let aux = t.(i) in
+  t.(i)<-t.(j);
+  t.(j)<-aux
+;;
+let retourne_tableaux t i=
+  for j=0 to i/2 do
+    echange t j (i-j)
+  done;
+;;
+
+let maximum_tableaux t i = let k = ref 0 in
+  for j = 0 to i do
+    if t.(j) > t.(!k) then k:= j
+    done;
+  !k
+;;
+
+let tri_pancake_tableaux t = let n = Array.length t in
+  for i = (n-1) downto 1 do
+    let aux = maximum_tableaux t i in 
+    retourne_tableaux t aux;
+    retourne_tableaux t i
+  done;
+  t
+;;

+ 5 - 0
TP2/tp2.mli

@@ -0,0 +1,5 @@
+val insere : int -> 'a array -> unit
+val tri_insertion : 'a array -> 'a array
+val minimum_reste : 'a list -> 'a * 'a list
+val tri_selection : 'a list -> 'a list
+val une_etape : 'a list -> 'a list

+ 91 - 0
TP3/tp3.ml

@@ -0,0 +1,91 @@
+type 'a file_array = {contenu: 'a array; mutable debut : int; mutable fin: int; mutable vide: bool};;
+
+let is_empty1 file =
+  file.vide
+;;
+
+let is_plein1 file =
+  not(file.vide) && (file.debut = file.fin)
+;;
+
+let add_tail1 x file = 
+	if is_plein1 file
+		then failwith "file pleine"
+else
+	begin
+		file.contenu.(file.fin)<-x;
+		file.fin <- ((file.fin +1) mod (Array.length (file.contenu)));
+		file.vide <- false;
+	end;
+;;
+
+
+
+let pop_head1 file =
+  if is_empty1 file
+    then failwith "file pleine"
+  else
+    begin
+      file.debut <- (file.debut + 1) mod (Array.length (file.contenu));
+      file.vide <- (file.debut=file.fin);
+      file
+    end;
+;;
+
+let length1 file =
+  if is_empty1 file
+    then 0
+else
+  let result = (file.fin - file.debut) in
+    if result>0 then result
+    else result + Array.length file.contenu
+;;
+
+let appartenance1 x file = 
+  if is_empty1 file 
+    then false
+  else 
+    begin
+      let t = (length1 file) and n = Array.length file.contenu in
+      let b = ref false and i = ref 0 in
+        while !i<t || !b do
+          if file.contenu.((file.debut + !i) mod n)=x then b:= true;
+          i:=!i+1
+        done;
+      !b
+    end
+;;
+
+type 'a file_list = {mutable sortie: 'a list; mutable entree: 'a list}
+
+let is_empty2 file = match (file.sortie,file.entree) with
+| ([],[]) -> true
+| _-> false
+;;
+
+let add_tail2 x file = 
+  file.entree <- x::file.entree;
+;;
+
+let rec aux file = match file.entree with
+| [] -> ()
+|t::q -> file.sortie <- t::file.sortie;
+  file.entree <- q;
+  aux file
+;;
+
+
+let rec normalize file = 
+  if file.sortie = [] then aux file
+;;
+
+let pop_head2 file =
+  normalize file;
+    if file.sortie = [] then failwith "liste vide"
+    else
+      begin
+      let t::q = file.sortie in
+      file.sortie <- q;
+      t
+      end
+;;

+ 5 - 0
test1/.vscode/settings.json

@@ -0,0 +1,5 @@
+{
+    "ocaml.sandbox": {
+        "kind": "global"
+    }
+}

+ 1 - 0
test1/_build/.lock

@@ -0,0 +1 @@
+27892

+ 5 - 0
test1/_build/log

@@ -0,0 +1,5 @@
+# dune init project helloworld
+# OCAMLPARAM: unset
+# Shared cache: disabled
+# Workspace root: /home/ghastrod/Documents/dev/OCaml/test1
+# Auto-detected concurrency: 2

+ 4 - 0
test1/helloworld/bin/dune

@@ -0,0 +1,4 @@
+(executable
+ (public_name helloworld)
+ (name main)
+ (libraries helloworld))

+ 1 - 0
test1/helloworld/bin/main.ml

@@ -0,0 +1 @@
+let () = print_endline "Hello, World!"

+ 26 - 0
test1/helloworld/dune-project

@@ -0,0 +1,26 @@
+(lang dune 3.6)
+
+(name helloworld)
+
+(generate_opam_files true)
+
+(source
+ (github username/reponame))
+
+(authors "Author Name")
+
+(maintainers "Maintainer Name")
+
+(license LICENSE)
+
+(documentation https://url/to/documentation)
+
+(package
+ (name helloworld)
+ (synopsis "A short synopsis")
+ (description "A longer description")
+ (depends ocaml dune)
+ (tags
+  (topics "to describe" your project)))
+
+; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project

+ 0 - 0
test1/helloworld/helloworld.opam


+ 2 - 0
test1/helloworld/lib/dune

@@ -0,0 +1,2 @@
+(library
+ (name helloworld))

+ 2 - 0
test1/helloworld/test/dune

@@ -0,0 +1,2 @@
+(test
+ (name helloworld))

+ 0 - 0
test1/helloworld/test/helloworld.ml


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

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

+ 94 - 0
test2/AlgoTriage.ml

@@ -0,0 +1,94 @@
+let rec insereprof x l = match l with
+| [] -> [x]
+| t::q when t<x -> t::(insereprof x q)
+| _-> x::l;;
+
+let rec tri_insertion l = match l with
+| [] -> []
+| t::q -> insereprof t (tri_insertion q);;
+
+let echange t i j =
+  let x = t.(i) in
+    t.(i) <- t.(j);
+    t.(j)<- x
+;;
+
+let minimum t i =
+  let m = ref i in
+    for k = i+1 to Array.length t -1 do
+      if t.(k)<t.(!m) then m:=k
+      done;
+      !m
+;;
+
+let tri_selection t =
+  for i=0 to Array.length t -2 do
+    echange t i (minimum t i)
+  done;
+  t
+;;
+
+let 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-1)>t.(k) then
+        begin
+          echange t (k-1) k;
+          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
+;;
+
+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)
+;;
+
+let partition2 t d f =
+  let i = ref d in
+    for j = d+1 to f do
+      if t.(j)<=t.(d) then
+        begin
+          i := !i+1;
+          echange t !i j;
+        end
+      done;
+      echange t d !i;
+      !i;
+;;
+
+let rec tri_rapide_aux t d f=
+  if f>d then
+    begin
+      let p = partition2 t d f in
+        tri_rapide_aux t d (p-1);
+        tri_rapide_aux t (p+1) f
+    end
+;;
+
+let tri_rapide t = tri_rapide_aux t 0 (Array.length t-1);;

+ 23 - 0
test2/AnalyseAlgo.ml

@@ -0,0 +1,23 @@
+let recherche a m = let ml = String.length a and al = String.length a and i = ref 0 and j = ref 0 in
+  while !i < al-ml-1 do
+    begin
+      while (!j<ml) && (m.[ !j] = a.[ !i]) do
+        begin
+          i := !i+1;
+          j := !j +1
+
+        end
+      done;
+      if !j = ml then
+        i := al-ml +1
+      else
+        begin
+          i := !i - !j+1;
+          j:=0
+        end
+    end
+  done;
+  !j = ml;;
+
+
+

+ 75 - 0
test2/Arbres.ml

@@ -0,0 +1,75 @@
+type 'a arbre1 =
+  | Vide
+  | N of 'a * 'a arbre1 * 'a arbre1
+;;
+
+let test1 = N(2,N(1,Vide, Vide), N(4,N(6,Vide,Vide), Vide));;
+
+let rec nb_sommet f = match f with
+| Vide -> 0
+| N(_,b,c) -> 1 + nb_sommet b + nb_sommet c
+;;
+
+let rec nb_noeud f = match f with
+| Vide -> 0
+| N(n,Vide,Vide) -> 0
+| N(_,g,d) -> 1 + nb_noeud g + nb_noeud d
+;;
+
+let rec nb_feuille f = match f with
+| Vide -> 0
+| N(n,Vide,Vide) -> 1
+| N(_,g,d) -> nb_feuille g + nb_feuille d
+;;
+
+
+let rec hauteur f = match f with
+| Vide -> -1
+| N(n,a,b) -> if hauteur a > hauteur b then 1 + hauteur a
+else 1 + hauteur b
+;;
+
+let rec etiquette f = match f with
+| Vide -> failwith "stop"
+| N(r,Vide,Vide) -> r
+| N(r,g,Vide)-> max r (etiquette g)
+| N(r,Vide,d) -> max r (etiquette d)
+| N(r,g,d) -> max r (max (etiquette g) (etiquette g))
+;;
+(* Pas sur de celui au dessus *)
+let rec entier a = match a with
+| Vide -> true
+| N(_,Vide,Vide) -> true
+| N(_,g,Vide) ->false
+| N(_,Vide,d) ->false
+| N(_,g,d) ->entier g && entier d
+;;
+
+
+type 'a arbre2 =
+| F of 'a
+| N of 'a * 'a arbre2 * 'a arbre2
+;;
+
+let test2 = N(2,F(1),N(4,F(7), F(8)));;
+
+type ('f, 'n) arbre3 =
+| F of 'f
+| N of 'n * (('f, 'n) arbre3) * (('f,'n) arbre3)
+;;
+
+let test3 = N((+), N(( * ), F 7, N((-), F 4, F 2)), N(( * ), F 3, F 1))
+
+type 'a arbre4 = N of 'a * ('a arbre4 list);;
+
+let test4 = N(2, [N(3,[N(5, [])]); N(6,[N(8, []); N(4,[])]); N(7,[])]);;
+
+let rec nb_sommet2 f = match f with
+| N(_,[]) -> 0
+| N(r,b::q) -> 1 + (nb_sommet2 b) + (nb_sommet2 (N(r,q)))
+;;
+
+let rec hauteur2 f = match f with
+| N(_,[]) -> 0
+| N(r,b::q) -> max (1+ hauteur2 b) (1+hauteur2 (N(r,q)))
+;;

+ 44 - 0
test2/DM1.ml

@@ -0,0 +1,44 @@
+let fusion 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 =
+  let rec tri_fusion_aux t l u =
+    if (l < u) then
+      begin
+        let m = (l+u)/2 in
+        tri_fusion_aux t l m;
+        tri_fusion_aux t (m+1) u;
+        fusion t l m u;
+      end
+    in tri_fusion_aux t 0 (Array.length t - 1)
+;;

+ 176 - 0
test2/DS2.ml

@@ -0,0 +1,176 @@
+let fibo1 n = let acc1 = ref 1 and acc2 = ref 0 in
+  let acc3 = ref !acc2 in
+    for i=1 to n do
+      acc3 := !acc1 + 0;
+      acc1 := !acc1 + !acc2;
+      acc2 := !acc3
+    done;
+    !acc2
+;;
+
+let rec fibo2 n = match n with
+| 0 -> 0
+| 1 -> 1
+| _ -> fibo2 (n-2) + fibo2 (n-1)
+
+let rec fibo_aux n acc1 acc2 = match n with
+| 0 -> acc1
+| _ -> fibo_aux (n-1) (acc2) (acc1+acc2);;
+
+let rec aux n table = 
+  if table.(n) = -1 then
+    table.(n) <- (aux (n-1) table) + (aux (n-2) table);
+  table.(n);;
+
+let fibo4 n = let table = Array.make (n+1) (-1) in
+  table.(0) <- 0;
+  table.(1)<- 1;
+  aux n table
+;;
+let rec fibo5 n =
+  match n with
+  | 0 -> 0
+  | 1 -> 1
+  | 2 -> 1
+  | _ ->
+    let p = n / 2 in
+    let fp = fibo5 p in
+    let fp_plus_1 = fibo5 (p + 1) in
+    if n mod 2 = 0
+    then fp_plus_1 * fp + fp * (fp_plus_1 - fp)
+    else fp_plus_1 * fp_plus_1 + fp * fp
+  ;;
+
+  let rec appartenance x l =
+    match l with
+    | [] -> false
+    | hd :: tl -> x = hd || appartenance x tl;;
+    let rec test_ensemble l =
+      match l with
+      | [] -> true
+      | x :: xs -> not (appartenance x xs) && test_ensemble xs;;
+
+
+      let rec union l1 l2 =
+        match (l1, l2) with
+        | ([], l) -> l
+        | (l, []) -> l
+        | (x :: xs, y :: ys) ->
+            if x < y then x :: union xs l2
+            else if x > y then y :: union l1 ys
+            else x :: union xs ys
+          ;;
+
+          let rec intersection l1 l2 =
+            match (l1, l2) with
+            | ([], _) | (_, []) -> []
+            | (x :: xs, y :: ys) ->
+                if x < y then intersection xs l2
+                else if x > y then intersection l1 ys
+                else x :: intersection xs ys
+              ;;
+              let rec difference l1 l2 =
+                match (l1, l2) with
+                | ([], _) -> []
+                | (x :: xs, []) -> l1
+                | (x :: xs, y :: ys) ->
+                    if x < y then x :: difference xs l2
+                    else if x > y then difference l1 ys
+                    else difference xs ys
+                  ;;
+                  
+                  let rec compteur1 x n =
+                    if n - x < 0 then (0, n)
+                    else
+                      let a, remainder = compteur1 x (n - x) in
+                      (a + 1, remainder)
+                    ;;
+                    let rec compteur2 x n p =
+                      if n - x < 0 || p = 0 then (0, n)
+                      else
+                        let a, remainder = compteur2 x (n - x) (p - 1) in
+                        (a + 1, remainder)
+                      ;;
+                      
+                    ;;
+                  ;;
+                ;;
+              ;;
+            ;;
+          ;;
+        ;;
+      ;;
+    ;;
+  ;;
+;;
+
+let monaie = [|1; 2; 5; 10; 20; 50; 100; 200; 500; 1000; 2000; 5000|];;
+let monaie2 = [|5000; 2000; 1000; 500; 200; 100; 50; 20; 10; 5; 2; 1|];;
+let monaie2content = [|1; 10; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1|];;
+let monaieuk = [|30; 24; 12; 6; 3; 1|];;
+let monaieukcontent = Array.make (Array.length monaieuk) 0;;
+
+let compteur1 x n =
+  let a = ref 0 in
+  let n' = ref n in
+  while !n' - x >= 0 do
+    n' := !n' - x;
+    a := !a + 1
+  done;
+  (!a, !n')
+;;
+let compteur2 x n p =
+  let a = ref 0 in
+  let n' = ref n in
+  let p' = ref p in
+  while !n' - x >= 0 && !p' > 0 do
+    n' := !n' - x;
+    p' := !p' - 1;
+    a := !a + 1
+  done;
+  (!a, !n')
+;;
+let compteur3 x n p =
+  let a = ref 0 in
+  let n' = ref n in
+  let p' = ref p in
+  while !n' - x >= 0 && !p' > 0 do
+    n' := !n' - x;
+    p' := !p' - 1;
+    a := !a + 1
+  done;
+  if !n' > 0 then
+    (-1, !n')
+  else
+    (!a, !n')
+  ;;
+let rendu_illimite n =
+  let result = ref [] in
+  for k = 0 to Array.length monaie2 - 1 do
+    let a = ref 0 in
+    let ninterne = ref n in
+    let x = monaie2.(k) in
+    while !ninterne - x >= 0 do
+      ninterne := !ninterne - x;
+      a := !a + 1
+    done;
+    if !ninterne > 0 then
+      a := -1;
+    result := !result @ [!a]
+  done;
+  !result;;
+
+let rendu_illimite2 n =
+  let result = ref [] in
+  for k = 0 to Array.length monaie2 - 1 do
+    let a = ref 0 in
+    let x = monaie2.(k) in
+    let n' = ref n in
+    while !n' - x >= 0 do
+      n' := !n' - x;
+      a := !a + 1
+    done;
+    result := !result @ [!a]
+  done;
+  !result;;
+    

+ 181 - 0
test2/DiviserRegner.ml

@@ -0,0 +1,181 @@
+let fiboiter n = let x = ref 0 and y = ref 1 and aux = ref 0 in
+  for i = 1 to n do
+    aux := !y;
+    y := !y + !x;
+    x := !aux;
+  done;
+  !y
+;;
+
+let rec fiborecu n = match n with
+| 0 -> 0
+| 1 -> 1
+| _ -> fiborecu (n-1) + fiborecu (n-2);;
+
+let rec aux n table = 
+  if table.(n) = -1 then
+    table.(n) <- (aux (n-1) table) + (aux (n-2) table);
+  table.(n);;
+
+let fibo2 n = let table = Array.make (n+1) (-1) in
+  table.(0) <- 0;
+  table.(1)<- 1;
+  aux n table
+;;
+
+let m = Array.make_matrix 3 3 3;;
+m.(1).(2) <- 5
+
+(* let produitmatriciel a b = 
+  if Array.length a <> Array.length b.(0) then
+    print_endline ("error");
+  let result = Array.make_matrix (Array.length a) (Array.length b.(0)) 0 in
+  for i = 0 to (Array.length a)-1 do
+    let aux = ref 0 in
+    for j = 0 to Array.length a.(0)-1 do
+      
+    done;
+  done;
+  result
+;; *)
+
+
+let produit a b =
+  let p = Array.length a and ra = Array.length a.(0)
+    and rb = Array.length b and q = Array.length b.(0) in
+      if ra <> rb then
+        failwith "pb de dimension"
+      else
+        begin
+          let c = Array.make_matrix p q 0 in
+            for i = 0 to p-1 do
+              for j = 0 to q-1 do
+                for k = 0 to ra-1 do
+                  c.(i).(j) <- c.(i).(j) + a.(i).(k) * b.(k).(j)
+                done;
+              done;
+            done;
+            c
+        end
+      ;;
+
+let identite n = let c = Array.make_matrix n n 0 in
+    for i = 0 to (n-1) do
+      c.(i).(i) <- 1;
+    done;
+    c;;
+
+let rec exp_rapide a n = match n with
+  | 0 -> identite (Array.length a)
+  | _ -> let aux = exp_rapide a (n/2) in
+    if n mod 2 = 0 then produit aux aux
+    else produit (produit aux aux) aux;;
+
+let fibo n =
+  let a = Array.make_matrix 2 2 1 in
+    a.(0).(0) <- 0;
+  (exp_rapide a n).(0).(1);;
+
+let rechercheiter t x= let ln = Array.length t and bo = ref false in
+  for i = 0 to ln-1 do
+    if t.(i) = x then bo := true
+    done;
+    !bo;;
+
+let rechercheiterprof s x = 
+  let n = Array.length s and i = ref 0 in
+  while (!i<n) && (x<>s.(!i)) do
+    i:= !i+1
+  done;
+  !i<>n;;
+
+let rec rechercherecu_aux s x i= match i with
+| -1 -> false
+| _ -> (x = s.(i)) || rechercherecu_aux s x (i-1);;
+
+let rechrecuchap s x = rechercherecu_aux s x ((Array.length s)-1);;
+
+let rechdicoiter s x = let a = ref 0 and b = ref s.(Array.length s-1) in
+  while !a <> !b do
+    let c = (!a + !b)/2 in
+      if s.(c)>= x then
+        b := c
+      else
+        a := c+1
+  done;
+  (s.(!a) = x);;
+
+let rec recherchedicorecu s x g d =
+  if g = d then x = s.(g)
+  else
+    begin
+      let m = (g+d)/2 in
+        if s.(m)>= x then 
+          recherchedicorecu s x m d
+        else 
+          recherchedicorecu s x (m+1) d
+        end
+      ;;
+
+let recherchedicorecuchap s x = recherchedicorecu s x 0 (Array.length s-1);;
+
+let sommepoly a b = let c = Array.make (max (Array.length a) (Array.length b) ) 0 in
+    for i = 0 to Array.length c-1 do
+      c.(i) <- a.(i) + b.(i)
+    done;
+    c;;
+
+(* let produitpol a b = 
+  let n = Array.length a in
+    let c = Array.make (2*n) 0 in
+      for i = 0 to (n-1) do
+        (for j = 0 to (n-1) do
+          c.(i+j) <- c.(i+j) + a.(i) * b.(j)
+        done : unit);
+      done;
+      c
+    ;; *)
+
+let fusion c1 c2 c3 = 
+  let n = Array.length c1 in
+    let c = Array.make (2*n) 0 in
+      for k = 0 to (n/2-1) do
+        c.(k) <- c1.(k)
+      done;
+      for i = (n/2) to (n-1) do
+        c.(i) <- c1.(i) + c2.(i-n/2)
+      done;
+      for j = n to (3*n/2-1) do
+        c.(j) <- c2.(j-n/2) + c3.(j-n) 
+      done;
+      for l = (3*n/2) to (2*n-1) do
+        c.(l) <- c3.(l-n)
+      done;
+      c;;
+
+let difference a b =
+  let n = Array.length a in
+    let c = Array.make n 0 in
+      for k = 0 to (n-1) do
+        c.(k) <- a.(k) - b.(k)
+      done;
+      c;;
+let rec karatsuba a b = 
+  if (Array.length a = 1) then
+    [| a.(0)*b.(0); 0 |]
+  else
+    begin
+      let n = Array.length a in
+      let a1 = Array.sub a 0 (n/2) and
+          a2 = Array.sub a (n/2) (n/2) and
+          b1 = Array.sub b 0 (n/2) and
+          b2 = Array.sub b (n/2) (n/2) in
+        let c1 = karatsuba a1 b1 and
+            c3 = karatsuba a2 b2 in
+        let a12 = sommepoly a1 a2 and
+            b12 = sommepoly b1 b2 in
+        let c2 = difference (karatsuba a12 b12) (sommepoly c1 c3) in
+          fusion c1 c2 c3
+    end
+  ;;
+karatsuba [|1;2;3|] [|4;5;6|];;

+ 235 - 0
test2/Info_10_fev_2023.ml

@@ -0,0 +1,235 @@
+let curry f = function a-> (function b -> f (a,b));;
+let decurry f = function (a,b) -> f a b;;
+
+let u n = 
+  let u0 = ref 1.0 in
+  for i = 0 to n do
+    u0 := sin !u0
+  done;
+  !u0
+;;
+
+let u = ref 1. and n = ref 0 in
+  while !u > 0.0001 do
+    u := sin !u;
+    n := !n + 1
+  done;
+  !n;;
+
+let factoriter n =
+  let k = ref 1 in
+  for i = 2 to n do
+    k := !k * i
+  done;
+  !k;;
+
+let puissance x n = let p = ref 1 in 
+  for i = 1 to n do
+    p := !p * x
+  done;
+  !p;;
+
+let sum m n = let s = ref 0. and c = ref 0. in
+  for i = m to n do
+    c := !c +. 1.;
+    if i >= m then
+      s := !s +. 1. /. !c
+    done;
+  !s
+;;
+
+let pgcd a b = let c = ref a and d = ref b and e = ref 0 in
+  while !c mod !d <> 0 do
+    e := !c;
+    c := !d;
+    d := !e mod !d
+  done;
+  !d;;
+
+let valuation p n = let v = ref 0 and aux = ref n in 
+  while !aux mod p = 0 do 
+    v := !v +1;
+    aux := !aux / p
+  done;
+  !v;;
+
+let maximum a = let max = ref a.(0) in 
+  for i = 0 to Array.length(a)-1 do 
+    if a.(i) > !max then
+      max := a.(i)
+  done;
+  !max;;
+
+let mirroir t = 
+  let n = Array.length t in 
+    let u = Array.make n t.(0) in
+      for i = 0 to n-1 do
+        u.(i) <- t.(n-1-i)
+      done;
+    u;;
+
+let appartenance t x= let a = ref 0 and b = ref false in
+    while t.(!a) <> x && !a< Array.length t do 
+      a := !a +1;
+    done;
+    if !a > 0 then
+      b := true;
+    !b
+    ;;
+
+let appartprof t x = let n = Array.length t and i = ref 0 in
+    while !i<n && x <> t.(!i) do
+      i := !i+1
+    done;
+    !i<n;;
+
+let appartsenti t x = let n = Array.length t and i = ref 0 in 
+    let aux = t.(n-1) in 
+      t.(n-1) <- x;
+      while x<> t.(!i) do 
+        i := !i+1
+      done;
+      (!i<(n-1) )||(x=aux );;
+
+let permut t = let n = Array.length t in 
+  let b = ref true in
+    for i = 0 to n-1 do 
+      if t.(i)>=n || t.(0)<0 then
+        b := false;
+      for j=i+1 to n-1 do 
+        if t.(i)=t.(j) then
+          b := false
+        done;
+      done;
+      !b;;
+
+let f x = x*x;;
+let u u0 n = let un = ref u0 in 
+  for k= 0 to n do 
+    un := f !un
+  done;
+  !un;;
+
+let rec suite_rec u0 n = 
+  if n= 0 then
+    u0
+  else f (suite_rec u0 (n-1));;
+
+let factoiter n = let u = ref 1 in
+  for k=1 to n do 
+    u := !u * k
+  done;
+  !u;;
+
+let rec factorecu n = match n with
+| 0 -> 1
+| _ -> n*factorecu (n-1);;
+
+let rec puissancerecu a n = match n with
+| 0 -> 1
+| _ -> a* puissancerecu a (n-1);;
+
+let puissanceiter a n = let b = ref 1 in 
+for k=1 to n do 
+  b := !b * a
+done;
+!b;;
+
+
+let rec carrerecu b = match b with
+| 0 -> 0
+| _ -> carrerecu (b-1) + 2*b -1
+
+let rec sumpq p q = match q with
+| 0 -> p
+| _ -> sumpq (p+1) (q-1);;
+
+let rec productpq p q = match q with
+| 0 -> 0
+| _-> (productpq p (q-1))+q;;
+
+let rec minimumtab t =
+  let n = Array.length t in
+    if n=1 then
+      t.(0)
+    else
+      let m = minimumtab (Array.sub t 1 (n-1)) in 
+        if t.(0)<m then
+          t.(0)
+        else
+          m;;
+
+let rec minimumtabindice t =
+  let n = Array.length t in
+    if n=1 then
+      0
+    else
+      let m = 1+minimumtabindice (Array.sub t 1 (n-1)) in 
+        if t.(0)<t.(m) then
+          0
+        else
+          m;;
+
+let rec min2_aux t i = 
+  let n = Array.length t in 
+    if i =n-1 then
+      i
+    else
+      let m = min2_aux t (i+1) in 
+        if t.(i)<t.(m) then
+          i
+        else
+          m;;
+let min2 t = min2_aux t 0;;
+
+let rec minmax_aux t i = 
+  let n = Array.length t in 
+    if i =n-1 then
+      (i,i)
+    else
+      let (m,o) = minmax_aux t (i+1) in 
+        match i with
+        | i when t.(i)<t.(m) -> (i,o)
+        | i when t.(i)>t.(o) -> (m,i)
+        | _ -> (m,o);;
+
+let minmax t = minmax_aux t 0;;
+
+let rec productegypt p q = match q with
+| 0 -> 0
+| q when q mod 2 = 0 -> productegypt (2*p) (q/2)
+| _ ->p+ productegypt p (q-1);;
+
+let rec divisioneucli1 a b =
+  if a<b then(0,a)
+  else
+    let q,r= divisioneucli1(a-b) b in 
+    (q+1,r);;
+
+let rec pgcd a b =
+  if b = 0 then a
+  else pgcd b (a mod b);;
+
+let rec pgcdprof a b = 
+  if a = b then a
+  else let r = snd (divisioneucli1 a b) in 
+    pgcdprof b r;;
+
+let rec pgcd2prof a b = match (a,b) with
+| (a,0) -> a
+| (a,b) when a<b -> pgcd2prof b a
+| _ -> pgcd2prof (a-b) b;;
+
+let rec fib n =
+  if n <= 0 then 0.
+  else if n = 1 then 1.
+  else fib (n-1) +. fib (n-2);;
+
+let rec coeffbinom n p = match (p,n) with
+| (0,n) -> 1
+| (p,n) when p = n-> 1
+| _ -> (coeffbinom (n-1) p) + (coeffbinom (n-1) (p-1));;
+
+let rec coeffbinom2duprof p n = match (p,n) with
+| (0,n) -> 1
+| _ -> (n* coeffbinom2duprof (p-1) (n-1))/(p);;

+ 38 - 0
test2/Info_10_fev_2023.mli

@@ -0,0 +1,38 @@
+val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c
+val decurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c
+val u : int -> float
+val factoriter : int -> int
+val puissance : int -> int -> int
+val sum : int -> int -> float
+val pgcd : int -> int -> int
+val valuation : int -> int -> int
+val maximum : 'a array -> 'a
+val mirroir : 'a array -> 'a array
+val appartenance : 'a array -> 'a -> bool
+val appartprof : 'a array -> 'a -> bool
+val appartsenti : 'a array -> 'a -> bool
+val permut : int array -> bool
+val f : int -> int
+val u : int -> int -> int
+val suite_rec : int -> int -> int
+val factoiter : int -> int
+val factorecu : int -> int
+val puissancerecu : int -> int -> int
+val puissanceiter : int -> int -> int
+val carrerecu : int -> int
+val sumpq : int -> int -> int
+val productpq : 'a -> int -> int
+val minimumtab : 'a array -> 'a
+val minimumtabindice : 'a array -> int
+val min2_aux : 'a array -> int -> int
+val min2 : 'a array -> int
+val minmax_aux : 'a array -> int -> int * int
+val minmax : 'a array -> int * int
+val productegypt : int -> int -> int
+val divisioneucli1 : int -> int -> int * int
+val pgcd : int -> int -> int
+val pgcdprof : int -> int -> int
+val pgcd2prof : int -> int -> int
+val fib : int -> float
+val coeffbinom : int -> int -> int
+val coeffbinom2duprof : int -> int -> int

+ 0 - 0
test2/Info_10_mars_2023.ml


+ 148 - 0
test2/Info_3_mars_2023.ml

@@ -0,0 +1,148 @@
+let rec deplace n i j k =
+  if n = 1 then
+    begin
+    print_string (string_of_int 1 ^ " -> " ^ string_of_int j);
+    print_newline ()
+    end
+  else
+    begin
+      deplace (n-1) i k j;
+      print_string (string_of_int 1 ^ " -> " ^ string_of_int j);
+      deplace (n-1) k j i;
+      print_newline ()
+    end
+  ;;
+
+  let hanoi n =
+    deplace n 1 2 3;;
+hanoi 10;;
+
+(* let rec a n a0 b0= match n with
+| 0 -> a0
+| _  -> (a (n-1) a0 +. b(n-1) b0) /. 2.
+and b n a0 b0 = match n with
+| 0 -> b0 
+| _ -> sqrt (a n a0 *. b n b0);; *)
+
+let rec correctan a0 b0 n = match n with
+| 0 -> a0
+| _ -> (correctan a0 b0 (n-1) +. (correctbn a0 b0 (n-1))) /. 2.
+and correctbn a0 b0 n = match n with
+| 0 -> b0
+| _-> sqrt ((correctan a0 b0 (n-1)) *. (correctbn a0 b0 (n-1)))
+
+let rec pair n = match n with
+| 0 -> true
+| _ -> impair (n-1)
+and impair n = match n with
+| 0 -> false
+| _-> pair (n-1);;
+
+let rec facto n = match n with
+| 0 -> 1
+| _ -> n * facto (n-1)
+
+let rec facto_aux n acc k = match k with
+| k when k=n -> acc
+| _ -> facto_aux n (acc*(k+1)) (k+1);;
+
+let facto_term n =
+  facto_aux n 1 0;;
+let rec facto_aux2 n acc= match n with
+| 0 -> acc
+| _ -> facto_aux2 (n-1) (acc*(n));;
+
+let facto_term2 n =
+  facto_aux2 n 1;;
+
+let rec puissance a n = match n with
+| 0 -> 1
+| _ -> a * puissance a (n-1);;
+
+
+let rec puissanceaux1 a n acc k = match k with
+| k when k=n -> acc
+| _ -> puissanceaux1 a n (acc*a) (k+1);;  
+
+let puissance_term1 a n =
+  puissanceaux1 a n 1 0;;
+
+let rec puissanceaux2 a n acc = match n with
+| 0 -> acc
+| _ -> puissanceaux2 a (n-1) (acc*a);;
+
+let puissance_term2 a n = 
+  puissanceaux2 a n 1;;
+
+let rec f_un n f acc k = match n with
+| k when k=n -> acc
+| _ -> f_un n f (f acc) (k+1);;
+
+let f_unterm1 n f u0 = f_un n f u0 0;;
+
+let rec f_un2 n f acc = match n with
+| 0 -> acc
+| _ -> f_un2 (n-1) f (f acc);;
+
+let f_unterm2 n f u0 = f_un2 n f u0;;
+
+let rec suminv n k acc = match k with
+| k when k=n -> acc
+| _ -> suminv n (k+1) (acc +. 1. /. ((float_of_int k)**2.))
+
+let rec suminvprof n acc = match n with
+| 1.0 -> acc
+| _ -> suminvprof (n-.1.0) (acc +.(1./.n)**2.);;
+
+let sommeint n = suminvprof (float_of_int n) 1.0;;
+
+let rec fibo_aux n acc1 acc2 = match n with
+| 0 -> acc1
+| _ -> fibo_aux (n-1) (acc2) (acc1+acc2);;
+
+let fibo n = fibo_aux n 0 1;;
+
+let rec pour phi d n = match n with
+| 0 -> d
+| _ -> phi (pour phi d (n-1));;
+
+let rec pourterm phi d n =match n with
+| 0 -> d
+| _ -> pourterm phi (phi d) (n-1);;
+
+let puissancepour a n = pour (function x -> a*x) 1 n;;
+
+let rec tantque cond phi d = match (cond d) with
+| true -> tantque cond phi (phi d)
+| false -> d;;
+
+let rec aux a x n= match n with
+| 0 -> x
+| _ -> aux a (a*x) (n-1);;
+
+let puissanceaux3 a n = aux a 1 n;;
+
+let rec auxfibo (x,y) n = match n with
+| 0 -> x
+| _ -> auxfibo (y, x+y) (n-1);;
+
+let auxfiboterm n = auxfibo (0,1) n;;
+
+(* let rec pgcd2prof a b = match (a,b) with
+| (a,0) -> a
+| (a,b) when a<b -> pgcd2prof b a
+| _ -> pgcd2prof (a-b) b;; *)
+
+let pgcd2iter a b = let c = ref a and d = ref b in
+  while !d <> 0 do
+    if !d > !c then
+      begin
+      let aux = !c in
+      c := !d;
+      d := aux
+      end
+    else
+      c := !c - !d
+    done;
+    !c
+  ;;

+ 168 - 0
test2/chemin.ml

@@ -0,0 +1,168 @@
+type point = {x:float;y:float}
+
+let p1 = {x=0.;y=0.}
+let p2 = {x=1.; y=1.}
+let distance m1 m2 =
+  let x1 = m1.x and y1 = m1.y and x2 = m2.x and y2 = m2.y in
+    let result = (x2 -. x1)**2. +. (y2 -. y1)**2. in
+  result
+;;
+
+let nuage = [|1.0,2.1; 6.4,7.9|] in
+  nuage.(1);;
+
+let sample_array = [| {x=57.; y=39.}; {x=83.; y=5.}; {x=8.9; y=5.9}; {x=3.6; y=61.}; {x=79.; y=3.}; 
+  {x=9.2; y=2.3}; {x=27.; y=26.}; {x=7.; y=54.}; {x=8.; y=73.}; {x=21.; y=98.} |]
+
+
+let distance_i nuage i = let min = ref 0. and aux = ref i in
+  for j = !aux+1 to Array.length nuage -1 do
+    let aux2 = distance nuage.(!aux) nuage.(j) in
+      if aux2 < !min then min := aux2
+      done;
+      !min
+;;
+
+let distance_mini nuage = distance_i nuage 0;;
+
+let distance_mini_1D nuage =
+  let n = Array.length nuage in
+  let min_dist = ref infinity in
+  for i = 0 to n - 2 do
+    let dist = nuage.(i+1).x -. nuage.(i).x in
+    if dist < !min_dist then min_dist := dist
+  done;
+  !min_dist
+;;
+
+(* merge two sorted arrays *)
+let fusion_array_h 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).x < t.(!j).x || (t.(!i).x = t.(!j).x && t.(!i).y < t.(!j).y) 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_array_h t =
+  let rec tri_fusion_aux t l u =
+    if (l < u) then
+      begin
+        let m = (l+u)/2 in
+        tri_fusion_aux t l m;
+        tri_fusion_aux t (m+1) u;
+        fusion_array_h t l m u;
+      end
+  in tri_fusion_aux t 0 (Array.length t - 1);
+  t
+;;
+
+let fusion_v 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).y <= t.(!j).y || (t.(!i).y = t.(!j).y && t.(!i).x <= t.(!j).x) 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_v t =
+  let rec tri_fusion_v_aux t l u =
+    if l < u then begin
+      let m = (l+u)/2 in
+      tri_fusion_v_aux t l m;
+      tri_fusion_v_aux t (m+1) u;
+      fusion_v t l m u;
+    end
+  in tri_fusion_v_aux t 0 (Array.length t - 1);
+  t
+;;
+
+let separation nuage_h nuage_v =
+  let n = Array.length nuage_h in
+  let i = ref 0 in
+  while !i < n && nuage_v.(!i).x <= nuage_h.(n/2).x do
+    i := !i + 1
+  done;
+  let nuage_g = Array.sub nuage_h 0 (n/2) in
+  let nuage_d = Array.sub nuage_h (n/2) (n - n/2) in
+  let nuage_vg = Array.sub nuage_v 0 !i in
+  let nuage_vd = Array.sub nuage_v !i (n - !i) in
+  (nuage_g, nuage_d, nuage_vg, nuage_vd)
+;;
+
+(* let (nuage_g, nuage_d, _, _) = t in nuage_g;; *)
+
+
+let bande_du_plan nuage_h nuage_v delta =
+  let n = Array.length (nuage_h) in
+  let xmed = nuage_h.(n/2).x and l = ref [] and cpt = ref 0 in
+  for i = n-1 downto 0 do
+    let x = nuage_v.(i).x in
+    if x <= xmed +. delta && x>= xmed -. delta then
+      begin
+        cpt := !cpt + 1;
+        l := nuage_v.(i)::(!l);
+      end;
+    done;
+    let b = Array.make (!cpt) nuage_h.(0) in
+    for k = 0 to !cpt - 1 do
+      b.(k)<- List.hd(!l);
+      l:= List.tl(!l)
+    done;
+  b
+;;
+
+let minimum_bande b delta =
+  let n = Array.length(b) and min = ref delta in
+  for i = 0 to n-2 do
+    let k = ref (i+1) and y = b.(i).y in
+      while !k<n && b.(!k).y < y +. !min do
+        let d = distance b.(!k) b.(i) in
+          if d<(!min) then
+            min:= d;
+          k:=!k+1
+          done;
+        done;
+        !min
+      ;;

+ 241 - 0
test2/datastructs.ml

@@ -0,0 +1,241 @@
+let intervertir file =
+  let a = Stack.pop file and b = Stack.pop file in
+    Stack.push b file;
+    Stack.push a file
+;;
+let p = Stack.create();;
+
+Stack.push 4 p;;
+Stack.push 3 p;;
+Stack.pop p;;
+
+Stack.length p;;
+
+
+let copie p =
+  let t = Stack.create() and q = Stack.create() in
+    while not (Stack.is_empty p) do
+      let aux = Stack.pop p in
+        Stack.push aux t;
+    done;
+    while not (Stack.is_empty t) do
+      let aux = Stack.pop t in
+        Stack.push aux p;
+        Stack.push aux q;
+    done;
+    q
+;;
+
+let rotation p = 
+  let q = Stack.create() and a = Stack.pop p in
+    while not (Stack.is_empty p) do
+      Stack.push (Stack.pop q) p
+    done;
+    Stack.push a p;
+    while not (Stack.is_empty q) do
+      Stack.push (Stack.pop q) p
+    done;
+;;
+
+type coord = float * float;;
+
+type couleur = Bleu;;
+Bleu;;
+
+type logarithme = Ln of float;;
+
+let evaluation x = let Ln a = x in log a;;
+
+evaluation (Ln 5.0);;
+
+type couleur2 = Bleu | Rouge | Jaune | Vert;;
+
+Vert;;
+
+type complex = Cartesien of float * float| Polaire of float * float;;
+
+let i = Cartesien (0., 1.);;
+
+let modulus z = match z with
+| Cartesien (x,y)-> sqrt(x**2. +. y**2. )
+| Polaire (r,t)-> r
+;;
+
+type nat = Zero | S of nat;;
+let iszero n = match n with
+| Zero -> true
+| _ -> false;;
+
+let quatre = S(S(S(S(Zero))));;
+let rec entier n = match n with
+| Zero -> 0
+| S m -> 1+ entier m
+;;
+
+let rec peano n = match n with
+| 0 -> Zero
+| _ -> S(peano (n-1));;
+
+peano 6;;
+
+let rec addition a b = match b with
+| Zero -> a
+| S m -> addition (S a) m;;
+
+addition (peano 5) (peano 6);;
+
+let rec multiplication m n = match m with
+| Zero -> Zero
+| S l -> addition n (multiplication l n);;
+
+multiplication (peano 2) (peano 2);;
+
+(* Vendredi 14 avril *)
+type 'a maList = Vide | Ajout of 'a*'a maList;;
+
+let liste2 = Ajout(1,Ajout(2,Ajout(3,Vide)));;
+
+let rec tete lister = match lister with
+| Vide  -> 0
+| Ajout (m,q) -> m;;
+
+let rec queue lister = match lister with
+| Vide -> Vide
+| Ajout (m,q) -> q;;
+
+let rec longueur lister = match lister with
+| Vide -> 0
+| Ajout (m,q) -> 1 + longueur q;;
+
+
+type entier_gauss = {real:int; ima:int}
+
+let i = {real=0; ima=1}
+
+let addition_gauss n1 n2 =
+  let result = {real= n1.real + n2.real; ima= n1.ima + n2.ima}in
+  result;;
+
+let multiplication n1 n2 =
+  let real1 = n1.real * n2.real - n1.ima * n2.ima and im1 = n1.real * n2.ima + n1.ima * n2.real in
+    let result = {real = real1; ima = im1} in
+    result;;
+
+let conjugaison n1 = 
+  let result = {real = n1.real; ima = -1 * n1.ima} in
+    result;;
+
+type 'a pile = PileVide | Ajout of 'a * 'a pile;;
+
+let creer_pile_vide ()= let x = PileVide in
+  x;;
+
+let etre_pile_vide p = match p with
+| PileVide -> true
+| _ -> false;;
+
+let empiler y p = let result = Ajout(y,p) in
+  result;;
+
+let depiler p = match p with
+| PileVide -> failwith "PileVide"
+| Ajout(t,q) -> q;;
+
+let sommet p = match p with
+| PileVide -> failwith "PileVide"
+| Ajout(t,q) -> t;;
+
+type 'a pile3 = 'a list;;
+
+let creer_pile_vide2 () = ([]:'a pile3);;
+
+let pile_vide2 (p:'a pile3) = match p with
+| [] -> true
+| _ -> false;;
+
+let pile_empiler2 y (p:'a pile3) = (y::p : 'a pile3);;
+
+let depiler2 (p: 'a pile3) = match p with
+| [] -> failwith"ntm"
+| t::q -> (q : 'a pile3);;
+
+let sommet (p: 'a pile3) = match p with
+| [] -> failwith"ntm"
+| t::q -> t;;
+
+type 'a pile4 = 'a list ref;;
+
+let creer_pile_vide3 () = (ref []:'a pile4);;
+
+let pile_vide2 (p:'a pile4) = match !p with
+| [] -> true
+| _ -> false;;
+
+let pile_empiler2 y (p:'a pile4) = p:=y::!p;;
+
+let depiler2 (p: 'a pile4) = match !p with
+| [] -> failwith"ntm"
+| t::q -> p:=q;t
+;;
+
+let sommet (p: 'a pile4) = match !p with
+| [] -> failwith"ntm"
+| t::q -> t;;
+
+type 'a pile5 = {mutable contenu : 'a list}
+
+let creer_pile_vide5 () = let x = {contenu = []} in
+  x
+;;
+
+let pile_vide5 (p:'a pile5) = match p.contenu with
+| [] -> true
+| _ -> false;;
+
+let pile_empiler5 y (p:'a pile5) = p.contenu <- y::p.contenu;;
+
+let depiler5 (p: 'a pile5) = match p.contenu with
+| [] -> failwith"ntm"
+| t::q -> p.contenu <- q;t
+;;
+
+let rec insere_pile5 x (p : 'a pile5) = match (p.contenu : 'a list) with
+| [] -> pile_empiler5 x p; p
+| t::q when x<=t -> pile_empiler5 x (p : 'a pile5);p
+| t::q -> p.contenu <- q; pile_empiler5 t (insere_pile5 x p);p
+;;
+
+let rec tri_inser_pile5 p = match p.contenu with
+| [] -> p
+| t::q -> p.contenu <- q; insere_pile5 t (tri_inser_pile5 p);;
+
+let pileatrier = {contenu = [5;3;8;90;34]};;
+
+tri_inser_pile5 pileatrier;;
+
+
+type symb = N of int | Op_binaire of (int -> int -> int) | Op_unaire of (int-> int);;
+
+type expr = symb list;;
+
+let machin = [N 3;N 10;N 5; Op_binaire (+) ; Op_binaire ( * )];;
+
+let rec aux p e = match p,e with
+| [n],[] -> n
+| t::q, Op_unaire f::r -> 
+  aux (f t)::q r
+|t1::t2::q, Op_binaire f::r ->
+  aux (f t1 t2)::q r
+| _, N n::r -> aux (n::p) r;;
+
+
+let eval e = aux [] e;;
+
+type arbre = F of int | Nun of symb * arbre | Nlin of symb * arbre*arbre;;
+
+let explarbre = Nlin (Op_binaire ( * ), Nlin(Op_binaire ( + ), F 10, F 5), F 3)
+
+let rec eval2 a = match a with
+| F x -> x
+| Nun(Op_unaire f, x) -> f (eval2 x)
+| Nlin(Op_binaire f, x, y) -> f (eval2 x) (eval2 y);;

+ 259 - 0
test2/dm2.ml

@@ -0,0 +1,259 @@
+type arbre_bin =
+  | Vide
+  | Noeud of int * arbre_bin * arbre_bin
+;;
+let bornesup = 1000000;;
+let borneinf = -1000000;;
+
+let ex1 =
+  Noeud (
+    34,
+    Noeud (
+      30,
+      Noeud (18, Noeud (10, Vide, Vide), Noeud (8, Vide, Vide)),
+      Noeud (20, Noeud (11, Vide, Vide), Noeud (14, Vide, Vide))
+    ),
+    Noeud (32, Noeud (30, Vide, Vide), Noeud (26, Vide, Vide))
+  )
+;;
+
+let etiquette f =
+  match f with
+  | Vide -> failwith "rien"
+  | Noeud (n, _, _) -> n
+;;
+
+let rec test_file f =
+  match f with
+  | Vide -> true
+  | Noeud (n, g, d) ->
+      if
+        n >= etiquette g
+        && n >= etiquette d
+        && test_file g
+        && test_file d
+      then
+        true
+      else
+        false
+;;
+
+let rec echange_etiquette f x = match f with
+| Vide -> Vide
+| Noeud(_,g,d)->Noeud(x,g,d)
+;;
+
+let rec percolation arbre =
+  match arbre with
+  | Vide -> Vide
+  | Noeud (n, Vide, Vide) -> Noeud (n, Vide, Vide)
+  | Noeud (n, g, d) ->
+      let plus_grand_fils =
+        if etiquette g >= etiquette d then
+          g
+        else
+          d
+      in
+      if etiquette plus_grand_fils > n then
+        Noeud (etiquette plus_grand_fils, percolation (echange_etiquette g n), d)
+      else
+        Noeud (n, percolation g, d)
+;;
+
+let rec supp_feuille arbre =
+  match arbre with
+  | Vide -> failwith "Impossible de supprimer une feuille d'un arbre vide"
+  | Noeud (n, Vide, Vide) -> Vide, n
+  | Noeud (n, g, Vide) ->
+      let nouveau_g, feuille_supprimee = supp_feuille g in
+      Noeud (n, nouveau_g, Vide), feuille_supprimee
+  | Noeud (n, Vide, d) ->
+      let nouveau_d, feuille_supprimee = supp_feuille d in
+      Noeud (n, Vide, nouveau_d), feuille_supprimee
+  | Noeud (n, g, d) ->
+      let nouveau_g, feuille_supprimee = supp_feuille g in
+      Noeud (n, nouveau_g, d), feuille_supprimee
+;;
+
+let supp_racine arbre =
+  match arbre with
+  | Vide -> failwith "Impossible de supprimer la racine d'un arbre vide"
+  | Noeud (n, gauche, droit) ->
+      let nouvel_arbre = echange_etiquette arbre (etiquette (fst (supp_feuille arbre))) in
+      percolation nouvel_arbre
+;;
+
+let rec insere x arbre = match arbre with
+| Vide -> Noeud(x,Vide,Vide)
+| Noeud(r,g,d)-> if x > r then 
+  begin
+    let rand = Random.int 2 in
+    if rand = 0 then Noeud(x,insere r g,d)
+    else Noeud(x,g,insere r d)
+  end
+else
+  begin
+    let rand = Random.int 2 in
+    if rand = 0 then Noeud(r,insere x g,d)
+    else Noeud(r,g,insere x d)
+  end
+;;
+
+let rec file_of_liste l = match l with
+| [] -> Vide
+| t::q-> insere t (file_of_liste q)
+;;
+
+let rec arbre_de_tas_aux i tas = match i>= Array.length tas with
+| true -> Vide
+| false -> 
+  let x = tas.(i) in
+  let sous_arbre_gauche = arbre_de_tas_aux (2*i +1) tas in
+  let sous_arbre_droite = arbre_de_tas_aux (2*i + 2) tas in
+  Noeud(x,sous_arbre_gauche,sous_arbre_droite)
+;;
+
+let arbre_de_tas tas = arbre_de_tas_aux 0 tas;;
+
+let rec taille arbre = match arbre with
+| Vide -> 0
+| Noeud(_,g,d)-> 1 + taille g + taille d
+;;
+
+
+let rec taille arbre =
+  match arbre with
+  | Vide -> 0
+  | Noeud(_, g, d) -> 1 + taille g + taille d
+;;
+
+
+let rec tas_d_arbre_aux i arbre tas =
+    match arbre with
+    | Vide -> ()
+    | Noeud(x, g, d) ->
+      tas.(i) <- x;
+      tas_d_arbre_aux (2 * i + 1) g tas;
+      tas_d_arbre_aux (2 * i + 2) d tas
+;;
+
+
+let tas_d_arbre arbre =
+  let n = taille arbre in
+  let tas = Array.make n 0 in
+  tas_d_arbre_aux 0 arbre tas;
+;;
+
+let est_valide_valeur v gauche droite n tas =
+  if gauche < n && tas.(gauche) > v then
+    false
+  else if droite < n && tas.(droite) > v then
+    false
+  else
+    true
+;;
+
+let rec est_tas i n tas =
+  if i >= n then
+    true
+  else
+    let gauche = 2 * i + 1 in
+    let droite = 2 * i + 2 in
+    let v = tas.(i) in
+    est_valide_valeur v gauche droite n tas && est_tas gauche n tas && est_tas droite n tas
+;;
+
+let verification_tas tas =
+  let n = Array.length tas in
+  est_tas 0 n tas
+;;
+
+let echange t i j =
+  let aux = t.(i) in
+  t.(i)<-t.(j);
+  t.(j)<-aux
+;;
+
+let rec remonter_aux i t =
+  if i = 0 || t.(i) <= t.((i - 1) / 2) then
+    ()
+  else
+    let parent = (i - 1) / 2 in
+    let temp = t.(i) in
+    t.(i) <- t.(parent);
+    t.(parent) <- temp;
+    remonter_aux parent t
+;;
+
+let remonter n t =
+  remonter_aux n t
+;;
+
+let insertion x t =
+  let n = Array.length t in
+  t.(n)<-x;
+  remonter n t;
+;;
+
+let creation_tab t = 
+  let resultat = Array.make 100 (-1) in
+  for i = 0 to Array.length t -1 do
+    insertion t.(i) resultat
+  done;
+;;
+
+let fils_max k t =
+  let fg = 2 * k + 1 in
+  let fd = 2 * k + 2 in
+  let n = Array.length t in
+  if fg < n && fd < n then
+    if t.(fg) > t.(fd) then
+      fg
+    else
+      fd
+  else if fg < n then
+    fg
+  else
+    k
+;;
+
+let rec descente_aux k n t=
+    let max_child_index = fils_max k t in
+    if max_child_index < n && t.(max_child_index) > t.(k) then
+      begin
+        let temp = t.(k) in
+        t.(k) <- t.(max_child_index);
+        t.(max_child_index) <- temp;
+        descente_aux max_child_index n t
+      end
+;;
+
+let descente t =
+  let n = Array.length t in
+  descente_aux 0 n t
+;;
+
+let suppression t =
+  let n = Array.length t in
+  if n > 0 then begin
+    t.(0) <- t.(n - 1);
+    descente (Array.sub t 0 (n - 1))
+  end
+;;
+
+let tri_tas t =
+  let n = Array.length t in
+  let resultat = Array.make n 0 in
+
+  for i = 0 to n - 1 do
+    insertion t.(i) resultat
+  done;
+
+  for i = 0 to n - 1 do
+    suppression resultat
+  done;
+
+  for i = 0 to n - 1 do
+    t.(i) <- resultat.(i)
+  done
+;;

+ 24 - 0
test2/hanoi.ml

@@ -0,0 +1,24 @@
+let rec hanoi n src dest spare =
+  if n = 0 then ()
+  else (
+    hanoi (n - 1) src spare dest;
+    print_endline ("Move disk " ^ string_of_int n ^ " from " ^ src ^ " to " ^ dest);
+    hanoi (n - 1) spare dest src
+  );;
+hanoi 2 "A" "B" "C";;
+
+let rec fibonacciterm n current next =
+  match n with
+  | 0 -> current
+  | 1 -> next
+  | _ -> fibonacciterm (n - 1) next (current + next);;
+
+let rec max_index lst start =
+  if start = (List.length lst) - 1 then
+    start  (* Cas de base : le dernier élément de la liste *)
+  else
+    let max_idx = max_index lst (start + 1) in
+    if List.nth lst start >= List.nth lst max_idx then
+      start
+    else
+      max_idx

+ 35 - 0
test2/hello.ml

@@ -0,0 +1,35 @@
+let max x y z = max (max x y) z;;
+max 4 6 7;;
+let rec pgcd a b =
+  if b = 0 then a
+  else pgcd b (a mod b);;
+let rec power base exponent =
+    if exponent = 0 then 1
+    else if exponent < 0 then
+      1 / power base (-exponent)
+    else base * power base (exponent - 1);;
+power 10 100;;
+
+let rec fib n =
+  if n <= 0 then 0.
+  else if n = 1 then 1.
+  else fib (n-1) +. fib (n-2);;
+
+  let curry f (x, y) = f x y;;
+  let uncurry f x y = f (x, y);;
+let module_of_complex re im = sqrt (re ** 2.0 +. im ** 2.0);;
+
+let egalite (num1, den1) (num2, den2) =
+  num1 * den2 = num2 * den1;;
+let rec sequence_term u n =
+  if n = 0 then u
+  else sequence_term (sin u) (n - 1);;
+
+let rec u n = match n with
+| 0 -> 2.0
+| _ -> (u (n-1) +. v (n-1))/. 2.0
+and v n = match n with
+| 0 -> 1.0
+| _ -> (2.0 *. v (n-1) *. u (n-1))/.(u (n-1) +. v (n-1));;
+
+u 50;;

+ 0 - 0
test2/hello.mli


+ 0 - 0
test2/test1.txt


+ 0 - 0
test2/test2.txt