Skip to content

Instantly share code, notes, and snippets.

@daoleno
Created January 11, 2018 11:29
Show Gist options
  • Save daoleno/9fde912759ab5e621a0923cda311c2b2 to your computer and use it in GitHub Desktop.
Save daoleno/9fde912759ab5e621a0923cda311c2b2 to your computer and use it in GitHub Desktop.
OCaml version hanoi tower
(* 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