TEX
The Towers of Hanoi implementd using TEX.
%
% The Towers Of Hanoi
% TeX Implementation
% Copyright (C) 1999 Amit Singh. All Rights Reserved.
% http://hanoi.kernelthread.com
%
% The number of disks is held in this counter
%
\newcount\ndisks
\ndisks=4
% Tower labels
%
\def\FROM{1}\def\USING{2}\def\TO{3}
% hanoi('from', 'using', 'to', ndisks)
%
\def\hanoi#1#2#3#4{
\ifnum#4=1
\movedisk\from#1\to#3
\else
{\advance#4 by-1 \hanoi#1#3#2#4}
\movedisk\from#1\to#3
{\advance#4 by-1 \hanoi#2#1#3#4}
\fi
}
% movedisk('from', 'to')
%
\def\movedisk\from#1\to#2{
move disk from tower #1 to tower #2\par
}
% main()
%
\hanoi\FROM\USING\TO\ndisks
\end
% __END__