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

This commit is contained in:
2023-10-02 15:03:09 +02:00
parent 8d5cfa14dc
commit 9319ab68cd
4 changed files with 55 additions and 25 deletions

View File

@ -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;;
```
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
```