kernelthread.com

ML

The Towers of Hanoi using the ML programming language.

(* The Towers Of Hanoi *) (* ML *) (* Copyright (C) 1998 Amit Singh. All Rights Reserved *) (* http://hanoi.kernelthread.com *) (* *) (* Tested under Moscow ML version 1.43 *) exception illegal; fun dohanoi(0, _, _, _) = nil | dohanoi(n, to, from, using) = dohanoi(n-1, using, from, to) @ [(from, to)] @ dohanoi(n-1, to, using, from); fun hanoi (n) = if n < 1 then raise illegal else dohanoi(n, 3, 1, 2);

Download

hanoi.ml