Created
January 11, 2018 11:29
-
-
Save daoleno/9fde912759ab5e621a0923cda311c2b2 to your computer and use it in GitHub Desktop.
OCaml version hanoi tower
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* move n discs from a to z (using third peg named x) *) | |
let rec hanoi move n a z x = if n = 0 then () else | |
(hanoi move (n-1) a x z ; move n a z ; hanoi move (n-1) x z a) | |
let printmove disc a b = print_endline | |
("Move disc " ^ (string_of_int disc) ^ " from " ^ a ^ " to " ^ b) ;; | |
hanoi printmove 4 "peg A" "peg C" "peg B" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment