vault backup: 2023-10-02 15:03:09

This commit is contained in:
Louis Gallet 2023-10-02 15:03:09 +02:00
parent 8d5cfa14dc
commit 9319ab68cd
Signed by: lgallet
SSH Key Fingerprint: SHA256:qnW7pk4EoMRR0UftZLZQKSMUImbEFsiruLC7jbCHJAY
4 changed files with 55 additions and 25 deletions

View File

@ -18,6 +18,30 @@
"source": false "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", "active": "88e153f7ea61ad97",
"lastOpenFiles": [ "lastOpenFiles": [
"Algo/Séminaire/Chapter 3 - Case analysis.md",
"Algo/Courses/Chapter 6 - Lists (Exercises).md",
"Algo/Courses/Chapter 6 - Lists.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/Exercices seminaire.md",
"Algo/Séminaire/Chapter 3 - Case analysis.md",
"Algo/Courses",
"Algo/CM/CM du 27 septembre.md", "Algo/CM/CM du 27 septembre.md",
"Algo/Séminaire/Chapter 5 - Recursivity.md", "Algo/Séminaire/Chapter 5 - Recursivity.md",
"COM-ADMR/Séjour international EPITA.md", "COM-ADMR/Séjour international EPITA.md",
@ -177,7 +202,6 @@
"Methodologie/Gestion.md", "Methodologie/Gestion.md",
"English", "English",
"README.md", "README.md",
"Algo/Séminaire/Remediation.md",
"COM-ADMR", "COM-ADMR",
"Methodologie", "Methodologie",
"Algo/Séminaire/Chapter 4 - A bit of imperative.md", "Algo/Séminaire/Chapter 4 - A bit of imperative.md",

View File

@ -1,12 +1,12 @@
## 1.1 - Product ## 1.1 - Product
``` ```Ocaml
let rec product = function let rec product = function
| [] -> 0 | [] -> 0
| x::t -> x + product t;; | x::t -> x * product t;;
``` ```
## 1.2 - Count ## 1.2 - Count
``` ```Ocaml
let rec count x n = let rec count x n =
if x = [] then if x = [] then
0 0
@ -19,7 +19,7 @@ let rec count x n =
``` ```
## 1.3 - Search ## 1.3 - Search
``` ```Ocaml
let rec search x n = let rec search x n =
if x = [] then if x = [] then
0 0
@ -32,7 +32,7 @@ let rec search x n =
``` ```
## 1.4 - $n^{th}$ ## 1.4 - $n^{th}$
``` ```Ocaml
let rec length l = let rec length l =
if l = [] then if l = [] then
0 0
@ -46,8 +46,24 @@ let rec nth x n =
Failwith "The list is too short" Failwith "The list is too short"
else else
let e::t = x in let e::t = x in
if e = x then if n = 0
1 + count t n return e
else else
count t n;; 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
```

View File

@ -87,7 +87,7 @@ _: int list = [1 ; 2 ; 3; 4]
## List manipulation ## List manipulation
### Traverse ### 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 ```Ocaml
# let p = (1, 2);; # let p = (1, 2);;
val p: int*int = (1,2) val p: int*int = (1,2)

View File

@ -14,24 +14,14 @@ else search (n/10) d
let rec chiffre_maximal n = let rec chiffre_maximal n =
  if n < 10 && n > 0 then   if n < 10 && n > 0 then
    n     n
  else   else
    let dernier_chiffre = n mod 10 in     let dernier_chiffre = n mod 10 in
    let reste = n / 10 in     let reste = n / 10 in
    let max_reste = chiffre_maximal reste in     let max_reste = chiffre_maximal reste in
    if dernier_chiffre > max_reste then     if dernier_chiffre > max_reste then
      dernier_chiffre       dernier_chiffre
    else     else
      max_reste;;
      max_reste
``` ```