Jump to content

User:Abhishek ganguly/test1

From Wikipedia, the free encyclopedia

Towers of Hanoi

[edit]
Recursive algorithm
  • move(disks:3, from:A, to:C, using:B)
    First move the top 2 disks to the intermediate peg B
    • move(disks:2, from:A, to:B, using:C)
      First move the top 1 disks to the intermediate peg C
      • move(disks:1, from:A, to:C, using:B)
        First move the top 1 disks to the intermediate peg B. As only one disk to be moved, so skip the move-smaller-disks-first branch
        Move/display-as-moved the disk no. 1 form peg:A to peg:C
        Cleanup the intermediate peg B by moving all of its disks to C