From a6b2e44d8a7c54e8e48b8d7ac4295afa03206fd2 Mon Sep 17 00:00:00 2001 From: mustafaismail98 <81989516+mustafaismail98@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:27:17 +0000 Subject: [PATCH 1/2] Premiers exo fait --- .local/share/rippkgs-index.sqlite | 1 + .replit | 17 ++++++++++++ 01/.task.ml.2635795876~ | 31 +++++++++++++++++++++ 01/task.ml | 45 +++++++++++++++++++++++++++++++ dune | 0 5 files changed, 94 insertions(+) create mode 120000 .local/share/rippkgs-index.sqlite create mode 100644 01/.task.ml.2635795876~ mode change 100644 => 100755 dune diff --git a/.local/share/rippkgs-index.sqlite b/.local/share/rippkgs-index.sqlite new file mode 120000 index 0000000..f5c5124 --- /dev/null +++ b/.local/share/rippkgs-index.sqlite @@ -0,0 +1 @@ +/etc/replit/rippkgs-indices/stable-23_11.sqlite \ No newline at end of file diff --git a/.replit b/.replit index b26e2f4..4934670 100644 --- a/.replit +++ b/.replit @@ -12,3 +12,20 @@ start = "ocamllsp" [nix] channel = "stable-23_11" + +[packager] +language = "dotnet" + +[packager.features] +packageSearch = true + +[env] +DOTNET_NOLOGO = "1" +DOTNET_CLI_TELEMETRY_OPTOUT = "1" + +[gitHubImport] +requiredFiles = [".replit", "replit.nix"] + +[deployment] +run = ["dotnet", "run"] +deploymentTarget = "cloudrun" diff --git a/01/.task.ml.2635795876~ b/01/.task.ml.2635795876~ new file mode 100644 index 0000000..7409cae --- /dev/null +++ b/01/.task.ml.2635795876~ @@ -0,0 +1,31 @@ +(* Ex O1 *) +let char_succ c = + if c < '\255' then c |> int_of_char |> succ |> char_of_int + else + '\000' + + +(* Ex O2 *) +let string_cons c s = String.make 1 c ^ s + + + +let _ =int_of_float (sqrt (float_of_int (int_of_string "81"))) + +let _ = + let string_to_int = int_of_string "81" in + let int_to_float = float_of_int string_to_int in + let square_root = sqrt int_to_float in + let d = int_of_float square_root in +d + + +let _ = + let cr = "cream" in + let i_u_we = + let sr = string_cons 's' cr in + "I " ^ sr ^ ", you " ^ sr ^ ", we all " ^ sr in + i_u_we ^ " for ice " ^ cr + + +let f = let c = ref 0 in fun x -> c := !c + x; !c \ No newline at end of file diff --git a/01/task.ml b/01/task.ml index e69de29..ad25ebb 100644 --- a/01/task.ml +++ b/01/task.ml @@ -0,0 +1,45 @@ +(* Ex O1 *) +let char_succ c = + if c < '\255' then c |> int_of_char |> succ |> char_of_int + else + '\000' + + +(* Ex O2 *) +let string_cons c s = String.make 1 c ^ s + + +(* EX 03 *) +let _ =int_of_float (sqrt (float_of_int (int_of_string "81"))) + +let _ = + let string_to_int = int_of_string "81" in + let int_to_float = float_of_int string_to_int in + let square_root = sqrt int_to_float in + let d = int_of_float square_root in +d + + +(* EX 04 *) +let _ = + let cr = "cream" in + let i_u_we = + let sr = string_cons 's' cr in + "I " ^ sr ^ ", you " ^ sr ^ ", we all " ^ sr in + i_u_we ^ " for ice " ^ cr + + +(* Pour info *) +let f = let c = ref 0 in fun x -> c := !c + x; !c + +(* Fonctions Récursives *) +(* EX1 *) + +let rec char_range lo hi = + if lo > hi then + "" + else + let next_char = char_succ lo in + string_cons lo (char_range next_char hi) + + diff --git a/dune b/dune old mode 100644 new mode 100755 From aa67e0441dfff34c72dcbf132441d3292f22b549 Mon Sep 17 00:00:00 2001 From: mustafaismail98 <81989516+mustafaismail98@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:37:07 +0000 Subject: [PATCH 2/2] 2eme jour --- 01/task.ml | 17 +++++- 02/lecture.md | 17 +++--- 02/task.ml | 53 +++++++++++++++++ 02/tutorial.md | 2 +- 03/task.ml | 156 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 233 insertions(+), 12 deletions(-) create mode 100644 02/task.ml create mode 100644 03/task.ml diff --git a/01/task.ml b/01/task.ml index ad25ebb..3c1ddda 100644 --- a/01/task.ml +++ b/01/task.ml @@ -10,14 +10,16 @@ let string_cons c s = String.make 1 c ^ s (* EX 03 *) -let _ =int_of_float (sqrt (float_of_int (int_of_string "81"))) +let _ = int_of_float (sqrt (float_of_int (int_of_string "81"))) let _ = let string_to_int = int_of_string "81" in let int_to_float = float_of_int string_to_int in let square_root = sqrt int_to_float in - let d = int_of_float square_root in -d + let d = int_of_float square_root in + + +int_of_float (sqrt (float_of_int (int_of_string "81"))) (* EX 04 *) @@ -43,3 +45,12 @@ let rec char_range lo hi = string_cons lo (char_range next_char hi) + +(* Lists *) +let swap lst = match lst with +| [] | [_] -> lst +| x :: y :: rest -> y :: x :: rest + +let repeat s n = +if n < 0 then [] +else List.init s(fun _ -> s) diff --git a/02/lecture.md b/02/lecture.md index 9f2bd3c..6a7b9cd 100644 --- a/02/lecture.md +++ b/02/lecture.md @@ -344,29 +344,30 @@ Voici quelques exemples . #### Calculer la longueur d'une liste ```ocaml let rec longueur ll = match ll with - | [] -> failwith "todo" - | x :: xs -> failwith "todo" + | [] -> 0 + | x :: xs -> 1 + longueur ``` #### Somme des éléments d'une liste ```ocaml let rec sum ll = match ll with - | [] -> failwith "todo" - | head :: tail -> failwith "todo" + | [] -> 0 + | x :: xs -> x + sum xs ``` #### Mettre des majuscules au début des mots ```ocaml let rec capitalize ll = match ll with - | [] -> failwith "todo" - | _ :: _ -> failwith "todo" (* String.capitalize_ascii *) + | [] -> [] + | x :: xs -> String.capitalize_ascii x :: capitalize xs ``` #### Rechercher un élément ```ocaml let rec contient ll = match ll with - | [] -> - | _ :: _ -> failwith "todo" + | [] -> false + | x :: xs when x = a -> true + | _ :: xs -> contient xs a ``` ## Fonctions d'ordre supérieur diff --git a/02/task.ml b/02/task.ml new file mode 100644 index 0000000..4fdf994 --- /dev/null +++ b/02/task.ml @@ -0,0 +1,53 @@ +(* EXO 02 *) + + +let swap lst = match lst with +| [] | [_] -> lst +| x :: y :: rest -> y :: x :: rest + + + +(* EXO 3 *) + +let repeat element n = +if n < 0 then [] +else + List.init n (fun _ -> element) + + +(* EXO 4 *) +let repeat_i_j i j = +if j < i then [] +else + List.init (j-i +1)(fun n -> i + n) + +(* EXO 5 *) + +let decr_list lst = +List.map (fun x -> x - 1) lst + +(* EXO 6 *) +let rec rev lst = +let rec rev_acc acc = function + | [] -> acc + | hd :: tl -> rev_acc (hd :: acc) tl +in +rev_acc [] lst + + +let rev l = + let rec rev_aux acc rest = + match rest with + | [] -> acc + | t :: q -> rev_aux ( t :: acc) + in +rev_aux [] l + +L'accumulateur, C'est un notion de PF, +Elle va avoir besoin de se rappeler de l'état intermediare +(* EXO 7 *) +let rec flat lst = +match lst with +| [] -> [] +| hd :: tl -> hd @ flat tl + diff --git a/02/tutorial.md b/02/tutorial.md index 7994ff6..842366e 100644 --- a/02/tutorial.md +++ b/02/tutorial.md @@ -150,7 +150,7 @@ is_sorted [1; 3; 2] ### Question 13 -Redéfinir `incr_list : int list -> int` en utilisant un itérateur. +Redéfinir `decr_list : int list -> int list` en utilisant un itérateur. ### Question 14 diff --git a/03/task.ml b/03/task.ml new file mode 100644 index 0000000..fe22a23 --- /dev/null +++ b/03/task.ml @@ -0,0 +1,156 @@ +(* EXO 1 *) + +type echec = Victoire | Nulle | Abondon + +let echec_partie fin_partie = match fin_partie with +| Victoire -> 1. +| Nulle -> 0.5 +| Abondon -> 0. + + +(* EXO 2 *) +type semaine = Samedi | Dimanche | Lundi | Mardi | Mercredi | Jeudi | Vendredi;; + +let est_un_weekend jour = match jour with +| Samedi | Dimanche -> true +| _ -> false + + +(* EXO 3 *) + +type etat = Metro | Boulot | Dodo | Vacances + +let transition_etat etat = + match etat with + | Metro -> Boulot + | Boulot -> Dodo + | Dodo -> Metro + | Vacances -> Vacances + +(* EXO 6 *) + +type familles = Pique | Coeur | Carreaux | Trefle + + +type carte = As of familles +| Sept of familles +| Huit of familles +| Neuf of familles +| Dix of familles +| Valet of familles +| Dame of familles +| Roi of familles + +type carte_a_jouer = { carte: carte; familles: familles} + + +(* EXO 7 *) + +let est_une_tete c = match c with +| Valet _ | Dame _| Roi _-> true +| _ -> false + + +let est_rouge c = match c with +| Roi (Coeur | Carreaux) +| Huit (Coeur | Carreaux) +| Neuf (Coeur | Carreaux) +| Dix (Coeur | Carreaux) +| Dame (Coeur | Carreaux) +| Sept (Coeur | Carreaux) +| As (Coeur | Carreaux) +| Valet (Coeur | Carreaux) -> true +| _ -> false + + +let score_normal v = match v with +| As (Pique | Coeur | Carreaux | Trefle) -> 13 +| Dix (Pique | Coeur | Carreaux | Trefle) -> 10 +| Roi (Pique | Coeur | Carreaux | Trefle) -> 4 +| Dame (Pique | Coeur | Carreaux | Trefle) -> 3 +| Valet (Pique | Coeur | Carreaux | Trefle) -> 2 +| Neuf (Pique | Coeur | Carreaux | Trefle) -> 0 +| Huit (Pique | Coeur | Carreaux | Trefle)-> 0 +| Sept (Pique | Coeur | Carreaux | Trefle) -> 0 + +let score_atout v = match v with +| As (Pique | Coeur | Carreaux | Trefle) -> 11 +| Dix (Pique | Coeur | Carreaux | Trefle) -> 10 +| Roi (Pique | Coeur | Carreaux | Trefle)-> 4 +| Dame (Pique | Coeur | Carreaux | Trefle) -> 3 +| Valet (Pique | Coeur | Carreaux | Trefle) -> 20 +| Neuf (Pique | Coeur | Carreaux | Trefle)-> 14 +| Huit (Pique | Coeur | Carreaux | Trefle)-> 0 +| Sept (Pique | Coeur | Carreaux | Trefle) -> 0 + + +let remporte_pli c1 c2 c3 c4 = + if est_rouge(c1) then true else false + + + + + +(* Constructeurs avec données *) + +type types = Entier of int | Flottant of float + + +let somme a b = + match (a, b) with + | (Entier x, Entier y) -> Entier(x + y) + | (Flottant x, Entier y) -> Flottant(x +. float_of_int(y)) + | (Entier x, Flottant y) -> Flottant(float_of_int(x) +. y) + | (Flottant x, Flottant y) -> Flottant(x +. y) + +let difference a b = + match (a, b) with + | (Entier x, Entier y) -> Entier (x - y) + | (Flottant x, Entier y) -> Flottant(x -. float_of_int(y)) + | (Entier x, Flottant y) -> Flottant(float_of_int(x) -. y) + | (Flottant x, Flottant y) -> Flottant (x -. y) + +let multiplication a b = + match (a, b) with + | (Entier x, Entier y) -> Entier (x * y) + | (Flottant x, Entier y) -> Flottant(x *. float_of_int(y)) + | (Entier x, Flottant y) -> Flottant(float_of_int(x) *. y) + | (Flottant x, Flottant y) -> Flottant (x *. y) + +let division a b = + match (a, b) with + | (Entier x, Entier y) -> if x mod y = 0 then Entier (x / y) else Flottant (float_of_int(x) /. float_of_int(y)) + | (Flottant x, Entier y) -> Flottant(x /. float_of_int(y)) + | (Entier x, Flottant y) -> Flottant(float_of_int(x) /. y) + | (Flottant x, Flottant y) -> Flottant (x /. y) + + +(* EXO 3 *) +type temperature = Celsius of float + + + + + +(* Types enregistrements *) +(* EXO 1 *) +type point = {x : float; y : float} +type couleur = Pique | Coeur | Carreaux | Trefle +type force = A | K | Q | J | Neuf | Huit | Sept | Dix +type carte = {couleur:couleur; force:force} +type carte_ou_Joker = Joker | Carte +let est_une_tete c = match c with {couleur = _ ; force = K | Q | J} -> true | _ -> false + +let compare_carte c1 c2 = +let int_of_force x = match x with +A -> 7 +| K -> 6 +| Q -> 5 +| J -> 4 +| Dix -> 3 +| Neuf -> 2 +| Huit -> 1 +| Sept -> 0 +in +if c1.couleur <> c2.couleur then (true: bool) +else int_of_force c1.force > int_of_force c2.force \ No newline at end of file