vault backup: 2023-09-29 14:33:01
This commit is contained in:
parent
42653756f2
commit
51cdedeae1
8
.obsidian/workspace.json
vendored
8
.obsidian/workspace.json
vendored
@ -13,7 +13,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/CM/CM du 27 septembre.md",
|
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||||
"mode": "source",
|
"mode": "source",
|
||||||
"source": false
|
"source": false
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "backlink",
|
"type": "backlink",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/CM/CM du 27 septembre.md",
|
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||||
"collapseAll": false,
|
"collapseAll": false,
|
||||||
"extraContext": false,
|
"extraContext": false,
|
||||||
"sortOrder": "alphabetical",
|
"sortOrder": "alphabetical",
|
||||||
@ -102,7 +102,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outgoing-link",
|
"type": "outgoing-link",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/CM/CM du 27 septembre.md",
|
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||||
"linksCollapsed": false,
|
"linksCollapsed": false,
|
||||||
"unlinkedCollapsed": true
|
"unlinkedCollapsed": true
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outline",
|
"type": "outline",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/CM/CM du 27 septembre.md"
|
"file": "Algo/Séminaire/Exercices seminaire.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -476,3 +476,32 @@ let prime n =
|
|||||||
in (n = 2) || (n mod 2 = 1 and check n 3)
|
in (n = 2) || (n mod 2 = 1 and check n 3)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Hanoi
|
||||||
|
```Ocaml
|
||||||
|
(* displays moves: source -> destination *)
|
||||||
|
|
||||||
|
let move source destination =
|
||||||
|
print_int source ;
|
||||||
|
print_string " -> " ;
|
||||||
|
print_int destination ;
|
||||||
|
print_newline()
|
||||||
|
;;
|
||||||
|
|
||||||
|
let hanoi n =
|
||||||
|
let rec play n source auxiliary destination =
|
||||||
|
if n = 1 then
|
||||||
|
move source destination
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
play (n-1) source destination auxiliary;
|
||||||
|
move source destination;
|
||||||
|
play (n-1) auxiliary source destination
|
||||||
|
end
|
||||||
|
in
|
||||||
|
if n < 0 then
|
||||||
|
invalid_arg "Hanoi: number of disks invalid"
|
||||||
|
else
|
||||||
|
play n 1 2 3 (* Appel initial avec les piquets source, auxiliaire et destination *)
|
||||||
|
;;
|
||||||
|
hanoi 3;; (* Pour déplacer 3 disques de la tige 1 à la tige 3 *)
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user