diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 745e8f7..98c16ca 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -18,6 +18,30 @@ "source": false } } + }, + { + "id": "652e1f58199c4ee5", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "Algo/Courses/Chapter 6 - Lists.md", + "mode": "source", + "source": false + } + } + }, + { + "id": "de55c93fc51612e0", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "Algo/Séminaire/Remediation.md", + "mode": "source", + "source": false + } + } } ] } @@ -158,11 +182,12 @@ }, "active": "88e153f7ea61ad97", "lastOpenFiles": [ - "Algo/Séminaire/Chapter 3 - Case analysis.md", - "Algo/Courses/Chapter 6 - Lists (Exercises).md", "Algo/Courses/Chapter 6 - Lists.md", - "Algo/Courses", + "Algo/Courses/Chapter 6 - Lists (Exercises).md", + "Algo/Séminaire/Remediation.md", "Algo/Séminaire/Exercices seminaire.md", + "Algo/Séminaire/Chapter 3 - Case analysis.md", + "Algo/Courses", "Algo/CM/CM du 27 septembre.md", "Algo/Séminaire/Chapter 5 - Recursivity.md", "COM-ADMR/Séjour international EPITA.md", @@ -177,7 +202,6 @@ "Methodologie/Gestion.md", "English", "README.md", - "Algo/Séminaire/Remediation.md", "COM-ADMR", "Methodologie", "Algo/Séminaire/Chapter 4 - A bit of imperative.md", diff --git a/Algo/Courses/Chapter 6 - Lists (Exercises).md b/Algo/Courses/Chapter 6 - Lists (Exercises).md index 7528ea6..0f68a4f 100644 --- a/Algo/Courses/Chapter 6 - Lists (Exercises).md +++ b/Algo/Courses/Chapter 6 - Lists (Exercises).md @@ -1,12 +1,12 @@ ## 1.1 - Product -``` +```Ocaml let rec product = function | [] -> 0 - | x::t -> x + product t;; + | x::t -> x * product t;; ``` ## 1.2 - Count -``` +```Ocaml let rec count x n = if x = [] then 0 @@ -19,7 +19,7 @@ let rec count x n = ``` ## 1.3 - Search -``` +```Ocaml let rec search x n = if x = [] then 0 @@ -32,7 +32,7 @@ let rec search x n = ``` ## 1.4 - $n^{th}$ -``` +```Ocaml let rec length l = if l = [] then 0 @@ -46,8 +46,24 @@ let rec nth x n = Failwith "The list is too short" else let e::t = x in - if e = x then - 1 + count t n + if n = 0 + return e else - count t n;; -``` \ No newline at end of file + nth t (n-1) ;; +``` + +## 1.5 - Maximum +```Ocaml +let max l = + if l = [] then + 0 + else + let maxi = 0 + let rec m = + let e::t = l + if e >= maxi then + maxi = e + else + m t +``` + diff --git a/Algo/Courses/Chapter 6 - Lists.md b/Algo/Courses/Chapter 6 - Lists.md index 07e138a..abf7035 100644 --- a/Algo/Courses/Chapter 6 - Lists.md +++ b/Algo/Courses/Chapter 6 - Lists.md @@ -87,7 +87,7 @@ _: int list = [1 ; 2 ; 3; 4] ## List manipulation ### Traverse -Sequential traverse have to solution, first is the list is empty, then you stop. Else if the list is not empty, we treat the head +Sequential traverse have to solution, first is the list is empty, then you stop. Else if the list is not empty, we extract the head and the tail, we treat the head and we traverse the trail (rec call) ```Ocaml # let p = (1, 2);; val p: int*int = (1,2) diff --git a/Algo/Séminaire/Remediation.md b/Algo/Séminaire/Remediation.md index e8ab718..f42db74 100644 --- a/Algo/Séminaire/Remediation.md +++ b/Algo/Séminaire/Remediation.md @@ -14,24 +14,14 @@ else search (n/10) d let rec chiffre_maximal n = -   if n < 10 && n > 0 then -     n -   else -     let dernier_chiffre = n mod 10 in -     let reste = n / 10 in -     let max_reste = chiffre_maximal reste in -     if dernier_chiffre > max_reste then -       dernier_chiffre -     else - -      max_reste +      max_reste;; ```