Files
EPITA/algo/ocaml/exo.ml
2025-09-15 18:05:39 +02:00

58 lines
1.3 KiB
OCaml

(* 2.2 *)
let power30 x =
let square x = x*x in
let power5 x =
square(square x) * x in
power5 (power5 x) * power5 x;;
(*2.3*)
let mirror x =
let u = x mod 10 and d= x/10 in
u*10+d;;
let abba x = x*100+mirror;;
let stammer x = abba(mirror x)*10000 + abba x;;
(*2.6*)
let sec_of_time h m s = h*3600+m*60+s;;
let time_to_sec s = (s/3600, s mod 3600/60, s mod 3600 mod 60);;
let add_time ha ma sa hb mb sb = time_of_sec(sec_of_time ha ma sa + sec_of_time hb mb sb);;
(*3.3*)
let min2 a b =
if a > b then b
else a;;
let max2 a b =
if a > b then a
else b ;;
let max3 a b c = if a>b && a>c then a else if b>c then b else c;;
let min3 a b c = if a<b && a<c then a else if b<c then b else c;;
(*3.7*)
let s a = match a with
x when x <= 0 -> 0.
| x when x <= 500 -> 4.6
| x when x <= 1000 -> 5.9
| x when x <= 2000 -> 6.5
| x when x <= 3000 -> 7.2
| _ -> failwith "";;
let e a = match a with
x when x <= 0 -> 0.
| x when x <= 500 -> 3.4
| x when x <= 1000 -> 4.6
| x when x <= 2000 -> 5.1
| x when x <= 3000 -> 6.9
| _ -> failwith "";;
let ex a = match a with
x when x <= 0 -> 0.
| x when x <= 500 -> 9.1
| x when x <= 1000 -> 11.
| x when x <= 2000 -> 13.5
| x when x <= 3000 -> 14.2
| _ -> failwith "";;