vault backup: 2023-09-25 15:02:04

This commit is contained in:
Louis Gallet 2023-09-25 15:02:04 +02:00
parent be9639c188
commit f1a9359db3
Signed by: lgallet
SSH Key Fingerprint: SHA256:qnW7pk4EoMRR0UftZLZQKSMUImbEFsiruLC7jbCHJAY

View File

@ -446,14 +446,21 @@ $$
$$ $$
## Exercise 4.12 - Prime number ## Exercise 4.12 - Prime number
```OCaml ```OCaml
(* V1 *)
let prime n = let prime n =
if n < 1 then if n < 1 then
invalid_args "n should not be inferior to zero" invalid_args "n should not be inferior to zero"
else if x = 2 then true else if x = 2 then true
else else
let rec pr n k = let rec pr n k =
if n mod k = 0 then if n = k then
true
else if n mod k = 0 then
false false
else else
check n (k + 1) check n (k + 1)
in pr n 2;; in pr n 2;;
(* V2 *)
```