From aa40e475bcae7ee7340c0f69580a37d9ad5ae425 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 6 Oct 2023 14:52:29 +0200 Subject: [PATCH] vault backup: 2023-10-06 14:52:29 --- Algo/Courses/Chapter 6 - Lists (Exercises).md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 =