Skip to content

Instantly share code, notes, and snippets.

@iolloyd
Created March 20, 2015 11:52
Show Gist options
  • Save iolloyd/596576a4d6ff954973dc to your computer and use it in GitHub Desktop.
Save iolloyd/596576a4d6ff954973dc to your computer and use it in GitHub Desktop.
Towers of Hanoi in ocaml
let rec hanoi f t x = function
| n when n = 1 ->
(Printf.printf "Move from %i to %i\n" f t)
| n ->;
hanoi f x t (n - 1); hanoi f t x 1; hanoi x t f (n - 1);
in hanoi 1 2 3 5 (* number of rings *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment