vault backup: 2023-09-15 14:08:51
This commit is contained in:
@ -331,6 +331,22 @@ let rec reverse_int n =
|
||||
|
||||
```
|
||||
|
||||
## Exercise 4.9 - Correction
|
||||
```Ocaml
|
||||
# let reverse = function
|
||||
| 0 -> " "
|
||||
| n -> string_of_int(n mod 10) ^ reverse(n/10);;
|
||||
val reverse : int -> string = <fun>
|
||||
|
||||
# let reverse_int =
|
||||
let rec rev org new_ =
|
||||
if org < 10 then
|
||||
new_ * 10 + org
|
||||
else
|
||||
rev (org/10)(new*10 + org mod 10)
|
||||
in rev n 0;;
|
||||
```
|
||||
|
||||
## Exercise 4.10
|
||||
|
||||
```Ocaml
|
||||
|
Reference in New Issue
Block a user