  A formal-linguistic approach for solving an entertaining task is made in this
paper. The well-known task of the Hanoi towers is discussed in relation to some
concepts of discrete mathematics. A context-free grammar which generate an
algorithm for solving this task is described. A deterministic pushdown
automation which in its work imitates the work of monks in solving the task of
the Hanoi towers is built.
