From b54bfd8de562edde0b4acccb43b28dcecb9e18e2 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 11 Sep 2025 16:59:25 +0200 Subject: [PATCH] ajout TP ocaml --- .gitignore | 1 + algo/ocaml/TPs/tp.ml | 29 +++++++++++++++++++++++++++++ algo/ocaml/tp.ml | 0 3 files changed, 30 insertions(+) create mode 100644 .gitignore create mode 100644 algo/ocaml/TPs/tp.ml create mode 100644 algo/ocaml/tp.ml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b8710a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.git diff --git a/algo/ocaml/TPs/tp.ml b/algo/ocaml/TPs/tp.ml new file mode 100644 index 0000000..6ef171a --- /dev/null +++ b/algo/ocaml/TPs/tp.ml @@ -0,0 +1,29 @@ + + +(*myst 100;;*) + +(*Fonction aux -----------*) +let sum x = (x mod 10)+(x /10);;(*somme des 4 chiffres*) + +let mirror x =(*inverse deux chiffres*) + let u = x mod 10 and d = x/10 in + u*10 +d;; + +let pal x = mirror(x mod 100) = x /100;;(* retourne true si x est un palindrome*) + +let parfait x = + int_of_float (sqrt(float_of_int x )*. 100.) mod 100 = 0;; + +(*---------------*) + +let ctc x = + if x/10 mod 2=0&&(x mod 10)mod 2<>0 then(* verif 3 pairs plus le dernier *) + if (sum(x mod 100)+sum(x/100))=9 then(* verfif somme = a 9*) + if x mod 25 = 0 then (*verfi divisible par 25*) + if pal (mirror(234 mod 100)*100 + mirror(1234 / 100)) = true then (*Verfir palindrome*) + if parfait x = true then x + else invalid_arg "Faux pas bon nombre" + else invalid_arg "Faux pas bon nombre" + else invalid_arg"Faux pas bon nombre" + else invalid_arg"Faux pas bon nombre" + else invalid_arg"Faux pas bon nombre";; diff --git a/algo/ocaml/tp.ml b/algo/ocaml/tp.ml new file mode 100644 index 0000000..e69de29