Last active
September 8, 2016 21:22
-
-
Save alarsyo/80e1ef8d671295c6ac2f33c3731a6ff6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
false || (1/0 = 0);; | |
true || (1/0 = 0);; | |
false && (1/0 = 0);; | |
true && (1/0 = 0);; | |
'Z' < 'a';; | |
"A long sentence to see how string comparisons work" > "a little one";; | |
(* to see how functions with several parameters work *) | |
let range a b = (a+b) / 2 ;; | |
let rangeBis (a,b) = (a+b) / 2;; | |
#trace range;; | |
#trace rangeBis;; | |
#untrace range;; | |
range 2 15;; | |
let another_ex a b c d e = a + b + c + d + e;; | |
#trace another_ex;; | |
another_ex 1 2 3 4 5;; | |
(* Exercice 2 *) | |
let x = 1 in 2x + x^2;; | |
let x = 1 in x <= 3;; | |
let x = 1 and y = 2 in | |
x < 10 && y > 0;; (* on remplace and par && *) | |
let x = 1 in 0 < x && x < 12;; | |
let b = let a = 1 in | |
a+1;; | |
let x = 1;; | |
let y = 2;; | |
x + y;; | |
(* Exercice 3*) | |
let mystery_number x = | |
if x >= 100 && x < 1000 then | |
let centaines = x / 100 in | |
let dizaines = x / 10 mod 10 in | |
let unites = x mod 10 in | |
if (centaines + dizaines + unites) <= 10 then | |
if (centaines * dizaines) < unites then | |
if dizaines = (centaines * unites) then true | |
else invalid_arg "invalid number" | |
else invalid_arg "invalid number" | |
else invalid_arg "invalid number" | |
else invalid_arg "entrez un nombre de 3 chiffres";; | |
(* Exercice 4 *) | |
let num_plaque n = | |
if n < 1000 || n > 9999 then invalid_arg "we need 4 figures" | |
else let milliers = n/1000 in | |
let centaines = n/100 mod 10 in | |
let dizaines = n/10 mod 10 in | |
let unites = n mod 10 in | |
let root = sqrt ( float_of_int n ) in | |
( milliers = centaines ) && ( dizaines = unites ) && ( root -. (float_of_int (int_of_float root))) = 0. ;; | |
(* Exercice 5 *) | |
let lendemain date = | |
let jour = int_of_string (String.sub date 0 2) in | |
let mois = int_of_string (String.sub date 3 2) in | |
let annee = int_of_string (String.sub date 6 4) in | |
let bissextile = ((annee mod 4 = 0) && (annee mod 100 <> 0)) || annee mod 400 = 0 in | |
let nb_jours_mois = | |
if mois = 4 || mois = 6 || mois = 9 || mois = 11 | |
then 30 | |
else if mois = 2 | |
then if bissextile then 29 else 28 | |
else 31 in | |
if jour = nb_jours_mois | |
then if mois = 12 | |
then "01" ^ "/" ^ "01" ^ "/" ^ (string_of_int (annee + 1)) | |
else "01" ^ "/" ^ (string_of_int (mois + 1)) ^ "/" ^ (string_of_int (annee)) | |
else (string_of_int (jour + 1)) ^ "/" ^ (string_of_int mois) ^ "/" ^ (string_of_int annee);; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment