vault backup: 2023-10-09 13:34:39
This commit is contained in:
parent
039c7bfd1c
commit
c2017e86b9
@ -114,6 +114,16 @@ let maximum = function
|
|||||||
let rec arith_list n a1 r =
|
let rec arith_list n a1 r =
|
||||||
if n <= 0 then []
|
if n <= 0 then []
|
||||||
else a1 :: arithmetic_list (n - 1) (a1 + r) r;;
|
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
|
## Exercise 2.2
|
||||||
@ -121,3 +131,13 @@ let rec arith_list n a1 r =
|
|||||||
let concatenate_lists lst1 lst2 =
|
let concatenate_lists lst1 lst2 =
|
||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user