Initially, the disks are all stacked on the leftmost post, with larger disks closer to the bottom and smaller disks closer to the top. For example, if there are three disks, the puzzle starts out looking like this.
The object is move all of the disks from the leftmost post to the rightmost post. So when the puzzle is solved, it looks like this.
But there are some rules that must be followed.
Number the moves, starting at move 1. For example, if the number of disks is 3, then the following would be printed.
1. Move a disk from post L to post R. 2. Move a disk from post L to post M. 3. Move a disk from post R to post M. 4. Move a disk from post L to post R. 5. Move a disk from post M to post L. 6. Move a disk from post M to post R. 7. Move a disk from post L to post R.The disk to be moved is always the top one on the post.
12. Move a disk from post M to post R. 13. Move a disk from post M to post L. 14. Move a disk from post R to post L. 15. Move a disk from post M to post R. 16. Move a disk from post L to post M. 17. Move a disk from post L to post R. 18. Move a disk from post M to post R.where the numbering has started from 12. It would return 7, since a total of 7 moves were made.
It is easy to move no disks. To move n disks from post A to post B, using post C as the other post, first ask a friend to move n-1 disks from post A to post C. Then move the largest disk from post A to post B. Finally, ask another friend to move n-1 disks from post C to post B.
Test your solution, and check whether the instructions that it prints work. When it is working, print it and turn it in. Be sure that your program is well written and well commented. Write the contract for your function into your file before you write the function body.