vault backup: 2023-09-14 16:20:59
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
|
||||

|
||||
## 0.1. Print
|
||||
If we want to print something in CAML, we have to use this structure
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||

|
||||
|
||||
<center><img src="https://gitea.louisgallet.fr/lgallet/epicours/raw/branch/main/Algo/S%C3%A9minaire/assets/recursivite-meme.png " width=512 height=auto /> </center>
|
||||
|
||||
### 5.1. Simple functions
|
||||
To create a recursive function we have to use this structure
|
||||
@ -64,3 +65,29 @@ A[ctd 3] --> B[ctd 2] --> C[ctd 1] --> D[ctd 0] --> E[ctd -1] --> F[ ] --> E -->
|
||||
> ctd is countdown
|
||||
|
||||
## 5.3. Several recursive calls
|
||||
A function that have several recursive calls is defind like this
|
||||
$$
|
||||
Fn = {1 -> \text{if } n\eqslantless{1} \brace{Fn+1+Fn+2} }
|
||||
$$
|
||||
**Fibonacci functions**
|
||||
```Ocaml
|
||||
let rec fibonacci n =
|
||||
if n = 0 then
|
||||
0
|
||||
else if n = 1 then
|
||||
1
|
||||
else
|
||||
fibonacci(n-1) + fibonacci(n-2);;
|
||||
|
||||
let add n =
|
||||
if n = 0 then
|
||||
false
|
||||
else
|
||||
even (n-1);;
|
||||
|
||||
let even n =
|
||||
if n = 0 then
|
||||
true
|
||||
else
|
||||
add (n-1);;
|
||||
```
|
Reference in New Issue
Block a user