From c2017e86b9d8d64447cc8514973b9762ff730b21 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 9 Oct 2023 13:34:39 +0200 Subject: [PATCH] vault backup: 2023-10-09 13:34:39 --- Algo/Courses/Chapter 6 - Lists (Exercises).md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Algo/Courses/Chapter 6 - Lists (Exercises).md b/Algo/Courses/Chapter 6 - Lists (Exercises).md index c732d15..3348764 100644 --- a/Algo/Courses/Chapter 6 - Lists (Exercises).md +++ b/Algo/Courses/Chapter 6 - Lists (Exercises).md @@ -114,6 +114,16 @@ let maximum = function let rec arith_list n a1 r = if n <= 0 then [] else a1 :: arithmetic_list (n - 1) (a1 + r) r;; + +(*Other solution*) +# let arith_list n a1 r = + if n <= 0 then + invalid_arg "invalid rank n" + else + let rec f ai = function + | 0 -> [] + | i -> (a1+(n-i)+r)::f(ai+r) (i-1) + in f ai n;; ``` ## Exercise 2.2 @@ -121,3 +131,13 @@ let rec arith_list n a1 r = let concatenate_lists lst1 lst2 = lst1 @ lst2;; ``` + +## Exercise 3.1 +```Ocaml +let growing i = + if i = [] then false + else + let rec grow = + let e::t = i in + let test = e in + if e