[Spe_TP1] Fin
This commit is contained in:
parent
d5b43a56e2
commit
3e47e865b4
@ -38,4 +38,47 @@ let rec concatener listes = match longueur listes with
|
||||
| _ -> concatener ([(List.hd listes)@(List.hd (List.tl listes))]@(List.tl (List.tl listes)));;
|
||||
concatener [[1;2;3];[2;1;3];[4;5;1;3];[1]];;
|
||||
concatener [];;
|
||||
List.concat [];;
|
||||
List.concat [];;
|
||||
|
||||
(* exercice 4*)
|
||||
|
||||
|
||||
|
||||
let rec recherche_dichomotique a v =
|
||||
if Array.length v = 0 then false
|
||||
else if a = v.((Array.length v)/2) then true
|
||||
else if a < v.((Array.length v)/2)
|
||||
then recherche_dichomotique a (Array.sub v 0 ((Array.length v)/2))
|
||||
else recherche_dichomotique a (Array.sub v ((Array.length v)/2+1) ((Array.length v)/2));;
|
||||
|
||||
|
||||
|
||||
|
||||
(*Exercice 5*)
|
||||
let est_phermier n = (*on prend un n >=2*)
|
||||
let t = ref true in
|
||||
if n = 2 then ()
|
||||
else for i = 2 to n/2 do
|
||||
if (n mod i) = 0 then t := false
|
||||
done ;
|
||||
!t;;
|
||||
|
||||
est_phermier 17;;
|
||||
est_phermier 14;;
|
||||
|
||||
|
||||
let est_vrm_phermier n = (* on prend aussi un n >=2*)
|
||||
let t = ref true and i = ref 2 in
|
||||
while !i <=(n/2) && !t do
|
||||
if (n mod !i) = 0 then t := false;
|
||||
i := !i + 1
|
||||
done;
|
||||
!t;;
|
||||
|
||||
|
||||
est_vrm_phermier 17;;
|
||||
est_vrm_phermier 17;;
|
||||
est_vrm_phermier 14;;
|
||||
est_vrm_phermier 14;;
|
||||
est_vrm_phermier 17;;
|
||||
est_vrm_phermier 13;;
|
||||
|
Loading…
Reference in New Issue
Block a user