exo
This commit is contained in:
BIN
algo/ocaml/.list.ml.un~
Normal file
BIN
algo/ocaml/.list.ml.un~
Normal file
Binary file not shown.
7
algo/ocaml/cours.ml
Normal file
7
algo/ocaml/cours.ml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
(*3 : construire une liste*)
|
||||||
|
|
||||||
|
let rec f = function
|
||||||
|
0->[]
|
||||||
|
|n -> n::f(n-1);;
|
||||||
|
(*val f:int -> int list =<fun>*)
|
||||||
|
|
||||||
16
algo/ocaml/list.ml
Normal file
16
algo/ocaml/list.ml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
let i arth n a r=
|
||||||
|
if n<= 0 then
|
||||||
|
invalid_arg "invalide arg"
|
||||||
|
else
|
||||||
|
let rec suite n a =
|
||||||
|
if n=0 then
|
||||||
|
[]
|
||||||
|
else
|
||||||
|
a::suite(n-1)(a+2)
|
||||||
|
in suite n a;;
|
||||||
|
|
||||||
|
let rec concat l l2 =
|
||||||
|
match l with
|
||||||
|
[]->l2
|
||||||
|
|e::l->e::concat l l2;;
|
||||||
|
|
||||||
15
algo/ocaml/liste.ml
Normal file
15
algo/ocaml/liste.ml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let rec maxprof lst = match lst with
|
||||||
|
[e] -> e
|
||||||
|
|e::l -> let m = maxprof l in if e>m then e else m
|
||||||
|
|[]->failwith "liste vide";;
|
||||||
|
|
||||||
|
let rec max2 a l = match l with
|
||||||
|
[] -> a
|
||||||
|
|e::l -> if a < e then max2 e l else max2 a l;;
|
||||||
|
maxprof [3;2;19;4];;
|
||||||
|
|
||||||
Reference in New Issue
Block a user