The Towers of Hanoi as a MATLAB program.
% The Towers Of Hanoi
% Copyright (C) 1998 Amit Singh. All Rights Reserved.
% Tested under PC MATLAB version 3.5j [May 3 1991]
% usage: hanoi(N, T3, T1, T2)
% where N = number of disks
% T3 = destination tower (typically 3)
% T1 = source tower (typically 2)
% T2 = auxiliary tower (typically 1)
function H = hanoi(n, t, f, u)
if n <= 0
P = hanoi(n-1, u, f, t);
fprintf('move %g --> %g\n', f, t);
Q = hanoi(n-1, t, u, f);