• 博客访问： 237608
• 博文数量： 23
• 博客积分： 2262
• 博客等级： 大尉
• 技术积分： 872
• 用 户 组： 普通用户
• 注册时间： 2004-12-26 15:59

2009年（3）

2008年（20）

2009-02-21 17:48:03

后来，这个传说就演变为汉诺塔游戏:
1.有三根杆子A,B,C。A杆上有若干碟子
2.每次移动一块碟子,小的只能叠在大的上面
3.把所有碟子从A杆全部移到C杆上
经过研究发现，汉诺塔的破解很简单，就是按照移动规则向一个方向移动金片：
如3阶汉诺塔的移动：A→C,A→B,C→B,A→C,B→A,B→C,A→C
此外，汉诺塔问题也是程序设计中的经典递归问题。

 `#!/usr/bin/perluse strict;use warnings;sub hnaoi { my (\$n, \$start,\$end, \$extra) = @_; if (\$n == 1) {    print "Move disk #1 from \$start to \$end.\n"; } else {    hnaoi (\$n-1, \$start,\$extra,\$end);    print "Move disk #\$n from \$start to \$end,\n";    hnaoi (\$n-1,\$extra,\$end,\$start); }}&hnaoi(5,'A','C','B');`

Move disk  #1 from A to C.
Move disk #2 from A to B,
Move disk  #1 from C to B.
Move disk #3 from A to C,
Move disk  #1 from B to A.
Move disk #2 from B to C,
Move disk  #1 from A to C.
Move disk #4 from A to B,
Move disk  #1 from C to B.
Move disk #2 from C to A,
Move disk  #1 from B to A.
Move disk #3 from C to B,
Move disk  #1 from A to C.
Move disk #2 from A to B,
Move disk  #1 from C to B.
Move disk #5 from A to C,
Move disk  #1 from B to A.
Move disk #2 from B to C,
Move disk  #1 from A to C.
Move disk #3 from B to A,
Move disk  #1 from C to B.
Move disk #2 from C to A,
Move disk  #1 from B to A.
Move disk #4 from B to C,
Move disk  #1 from A to C.
Move disk #2 from A to B,
Move disk  #1 from C to B.
Move disk #3 from A to C,
Move disk  #1 from B to A.
Move disk #2 from B to C,
Move disk  #1 from A to C.