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",
|
"direction": "horizontal",
|
||||||
"width": 300
|
"width": 300,
|
||||||
|
"collapsed": true
|
||||||
},
|
},
|
||||||
"right": {
|
"right": {
|
||||||
"id": "b83c16dd7908c658",
|
"id": "b83c16dd7908c658",
|
||||||
|
23
Exam.md
23
Exam.md
@ -1,16 +1,21 @@
|
|||||||
## Multiple insertion
|
## Multiple insertion
|
||||||
```Ocaml
|
```
|
||||||
let insert_mult n x lst =
|
# let insert_mult n x lst =
|
||||||
if n <= 0 then
|
if n <= 0 then
|
||||||
invalid_arg "insert_mult: n must be > 0"
|
invalid_arg "insert_mult: n must be > 0"
|
||||||
else
|
else
|
||||||
match lst with
|
let rec aux count = function
|
||||||
| [] -> []
|
| [] -> []
|
||||||
| z::f ->
|
|
||||||
let aux count = function
|
|
||||||
| [] -> x
|
|
||||||
| e::t ->
|
| e::t ->
|
||||||
if (count = n) then
|
if (count = n) then
|
||||||
e :: x :: t
|
e :: x :: aux 1 t
|
||||||
else aux (count + 1) t
|
else
|
||||||
in aux 1 t
|
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