Documented in Volume 1 of the UNIX Programmers Manual.
See /usr/doc/troff and trofftut on 4.2 BSD systems for additional online documentation on this.
See also nroff.
From gbergman@ucbtopaz.CC.Berkeley.ARPA UC Berkeley, CA USA
Subject: troff can do Towers of Hanoi
[Here is a short] file to do Towers of Hanoi using troff....
If you put it in a file "troff.hanoi", and do nroff -rr5 troff.hanoi,
it will output instructions for moving 5 rings from tower 1 to tower 2;
generally, just put the desired number of rings after the -rr on the
command line. In this case, you don't have a choice of initial state,
aside from choosing the number of rings.
.\"------------------troff.hanoi----------------------------------
.de H
.nr d \\$1-1
.if \\nd .H \\nd \\$2 \\$4 \\$3
Transfer ring \\$1 from tower \\$2 to tower \\$3.
.nr d \\$1-1
.if \\nd .H \\nd \\$4 \\$3 \\$2
..
Initial state: \nr rings all on tower A; #1 on top.
.H \nr A B C
Done!