From 92632d3039e30da3119093d9b1110e664bda88e7 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 11 Sep 2025 19:17:42 +0200 Subject: [PATCH] update tp --- algo/ocaml/tp.ml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/algo/ocaml/tp.ml b/algo/ocaml/tp.ml index e69de29..e995e65 100644 --- a/algo/ocaml/tp.ml +++ b/algo/ocaml/tp.ml @@ -0,0 +1,27 @@ +(*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(x mod 100)*100 + mirror(x / 100)) = true then (*Verfir palindrome*) + if parfait x = true then x + else invalid_arg "pas parfait" + else invalid_arg "pas un palindrome" + else invalid_arg"pas divisible par 25" + else invalid_arg"somme pas egale a 9" + else invalid_arg"3 non pairs";; + +ctc 2025;;