diff --git a/Algo/Courses/Chapter 6 - Lists (Exercises).md b/Algo/Courses/Chapter 6 - Lists (Exercises).md index 4c1029b..75d7761 100644 --- a/Algo/Courses/Chapter 6 - Lists (Exercises).md +++ b/Algo/Courses/Chapter 6 - Lists (Exercises).md @@ -54,7 +54,7 @@ val search 'a -> 'a list -> bool = | (_::t, n) -> nthrec(t, n-1) in ntrec(l, n);; -val nth 'a list -> 'a -> int = +val nth 'a list -> int -> 'a = ``` @@ -66,6 +66,18 @@ val nth 'a list -> 'a -> int = | hd :: tl -> let max_tail = max_value tl in if hd > max_tail then hd else max_tail;; + +(* v2 *) +# let max_value list = + if list = [] then + failwith "la list est vide" + else + let rec mv = match list with + | [x] -> x + | hd :: tl -> + let max_tail = max_value tl in + if hd > max_tail then hd else max_tail + in mv list;; ``` ## 1.6 - Bonus second @@ -90,7 +102,7 @@ val nth 'a list -> 'a -> int = ``` ## Exercise 2.1 -```Ocaml +``` let rec arith_list n a r =