# Difference between revisions of "Programming Assignment 4/zh CN"

4G - 编程作业4: 汉诺塔 (原作者: Tao Yue, 状态: 未更改)

```   |       |       |
|       |       |
*       |       |
***      |       |
*****     |       |
*******    |       |
```

```1 to 3
1 to 2
3 to 2
1 to 3
2 to 1
2 to 3
1 to 3
```

As stated in the section on recursion, recursion is one of the more difficult topics to grasp. Some people will look at this problem and find it extremely easy. Others will have a difficult time with it. However, once you get past the hurdle of understanding recursion, the actual coding of the program is relatively simple.

So, if you'd like to challenge yourself, stop reading right here. If you have a little trouble, keep reading for a small hint.

Hint: the problem, like all recursive problems, reduces itself, becoming simpler with each step. Remember the three-disc problem? You first create a two-disc tower on peg 2, which allows you to move the bottommost disc on peg 1 to peg 3. Then you move the two-disc tower on top of peg 3.

It's the same with four discs. First create a three-disc tower on peg 2, then move the biggest disc over to peg 3 and move the three-disc tower to peg 3. How do you create the three-disc tower? Simple. We already know how to move a three-disc tower from peg 1 to peg 3. This time, you're just moving from peg 1 to peg 2, then when the biggest peg is in place, you're moving the tower from peg 2 to peg 3. In this whole procedure, we can act as though the big disc doesn't exist, since it's guaranteed to be bigger than the others and thus poses no problem. Just utilize the three-disc solution, switching the numbers around.

Good luck!

 上一页 目录 下一页