Exmplo de algoritmo para solu??o da Torre de Hanoi

  • Post author:
  • Post category:Sem categoria

to solve (present, final)
1 is maximum the total number of discs
2 are destiny the final site of maximum
3 are maximum disc =
4 while disc > 0 does
5 if disc already is in destiny,
6 or, to move disc to destiny are successful then
7 if maximum disc = then
8 decremente maximum in 1
9 if maximum = 0 then
10 finish // ready solution
11 is destiny the final site of maximum
12 are destiny the site different from destiny and from
site in where it is disc
13 decremente disc in 1
14 are p and q the sites different from destiny
15 are disc the minor of discs of the tops of p and q
16 are destiny the site between p and q with the greater top