# 5.9 Consider a generalisation of the Towers of Hanoi problem discussed in §4.1, in which a fourth…

5.9     Consider a generalisation of the Towers of Hanoi problem discussed in §4.1, in which a fourth peg is added (Rohl

& Gedeon  (1983) ).  Fig.  5.23 gives the  inner  procedure H4

for generating a solution based on the use of the traditional procedure, here renamed  H3  to  underline  its  applicability to  the  three-peg  case.  The  function  f (n),  which  we leave

undefined, determines the number of  rings  to  be moved using only three pegs.

Fig.5.23.The inner procedure of a four-tower Hanoi procedure.

procedure H4(n:ndiscs; pl,p2,p3,p4 :pegtype);

begin

if n <> 0 then

begin

H4(n-f(n),pl ,p4,p3,p2);

H3(f(n),pl ,p2,p3);

H4(n-f(n),p4,p2,p3,pl )

end

end { of procedure “H4” };

Write a generalised procedure with the heading: procedu re H( m :npegs,n :ndiscs ; p  :pegt ype )

to generate  the  solution  for  m  pegs  assuming  the  existence of   a  function  f ( m,n},  whose  value  is  the  number   of  the

n rings to be moved using m-1 pegs. Note that pegt ype is now an array.