Hanoi Tower question Python

Source: Internet
Author: User

Count = 0
def Hanoi (N,SRC,MID,DST):
Global Count
if n = = 1:
Print ("{}:{}->{}". Format (1,SRC,DST))
Count + = 1
Else
Hanoi (N-1,src,dst,mid)
Print ("{}:{}->{}". Format (n, SRC, DST)) #第n个圆盘从第src位置移动到dst位置
Count + = 1
Hanoi (N-1,MID,SRC,DST)
Hanoi (3, "A", "B", "C")
Print (count)
#不显示对应序列号圆盘的简练写法
def move (n, a, B, c):
if n = = 1:
Print (A, '--', c)
Else
Move (N-1,A,C,B)
Print (A, '--', c)
Move (N-1,B,A,C)
Move (3, "A", "B", "C")

Hanoi Tower question Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.