"Python" Hanoi tower problem

Source: Internet
Author: User
Count = 0
def Hannuota (N,src,dst,mid): #n是圆盘数, SRC is the start, DST is the target, mid is over
Global Count
if n = = 1:
Print (' {}:{}->{} '. Format (1,SRC,DST)) #当圆盘是1时, move from the starting column to the target column
Count + = 1
Hannuota (N-1,SRC,MID,DST) #剩余的圆盘从A移到B柱子
Print (' {}:{}->{} '. Format (N,SRC,DST)) #最大的圆盘从A移到C柱子
Count + = 1
Hannuota (N-1,MID,DST,SRC) #剩余的圆盘从B柱子到C柱子
Hannuota (3, ' A ', ' C ', ' B ')
Print (count)

#我现在理解的是, imagine a 1,2,3,4,5 disc, first move the above four discs from a to B pillars, then move 5 from A to C pillars, then move the 1234 from B to the C pillar, and then break these actions into n=1.
#我也搞不懂, it's so hard!

"Python" Hanoi tower problem

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.