update tp
This commit is contained in:
@@ -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;;
|
||||||
|
|||||||
Reference in New Issue
Block a user