vault backup: 2023-10-30 10:14:11
This commit is contained in:
parent
3f39d3057c
commit
0a0932f378
3
.obsidian/workspace.json
vendored
3
.obsidian/workspace.json
vendored
@ -78,7 +78,8 @@
|
||||
}
|
||||
],
|
||||
"direction": "horizontal",
|
||||
"width": 300
|
||||
"width": 300,
|
||||
"collapsed": true
|
||||
},
|
||||
"right": {
|
||||
"id": "b83c16dd7908c658",
|
||||
|
35
Exam.md
35
Exam.md
@ -1,16 +1,21 @@
|
||||
## Multiple insertion
|
||||
```Ocaml
|
||||
let insert_mult n x lst =
|
||||
if n <= 0 then
|
||||
invalid_arg "insert_mult: n must be > 0"
|
||||
else
|
||||
match lst with
|
||||
| [] -> []
|
||||
| z::f ->
|
||||
let aux count = function
|
||||
| [] -> x
|
||||
| e::t ->
|
||||
if (count = n) then
|
||||
e :: x :: t
|
||||
else aux (count + 1) t
|
||||
in aux 1 t
|
||||
```
|
||||
# let insert_mult n x lst =
|
||||
if n <= 0 then
|
||||
invalid_arg "insert_mult: n must be > 0"
|
||||
else
|
||||
let rec aux count = function
|
||||
| [] -> []
|
||||
| e::t ->
|
||||
if (count = n) then
|
||||
e :: x :: aux 1 t
|
||||
else
|
||||
e :: aux (count + 1) t
|
||||
in
|
||||
match lst with
|
||||
| [] -> []
|
||||
| z::f -> z :: aux 0 f
|
||||
|
||||
val insert_mult: int -> 'a -> 'a list -> 'a list = <fun>
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user