Informatique/spe/TP4/main.ml
2020-05-02 18:15:27 +02:00

24 lines
471 B
OCaml

(* Exercice 1 *)
let rec invnaif l =
let rec perm c l = match l with
| [] -> 0
| h::t -> if c > h then (perm c t) + 1 else (perm c t) in
match l with
| [] -> 0
| h::t -> (perm h t) + (invnaif t);;
invnaif [3;2;1];;
(* Exercice 2 *)
let scinder l =
let rec aux acc1 c l = match l with
| [] -> ((List.rev acc1), [])
| h::t when c=0 -> ((List.rev acc1), t)
| h::t -> aux (h::acc1) (c-1) t
in
aux [] ((List.length l)/2) l ;;
scinder [1;2;3;4;5;6;7];;