Towers of Hanoi from https://youtu.be/DCKOcY-k2Es
- add
unix.cma
to inline using the Unix library when calling theHanoi.ml
program. You could have included it in a dune file.
ocaml unix.cma hanoi.ml
unix.cma
to inline using the Unix library when calling the Hanoi.ml
program. You could have included it in a dune file.ocaml unix.cma hanoi.ml
let () = | |
let instruct i src dsk = | |
Printf.printf "Moving disk %i from %s to %s\n%!" i src dsk; | |
Unix.sleep 1 | |
in | |
let rec hanoi i src dsk aux = | |
if i == 1 then instruct i src dsk else iterate i src dsk aux | |
and iterate i src dsk aux = | |
hanoi (i - 1) src aux dsk; | |
instruct i src dsk; | |
hanoi (i - 1) aux dsk src | |
in | |
hanoi 3 "A" "B" "C" |