python-Hanoi Recursive implementation

Source: Internet
Author: User

Excerpt from the commentary under the Liaoche Teacher's tutorial, personal memo, brain cells are dead

1 defMove from, to):#The animation effect needs to be mended by moving the plate from the2     Print( from,' -', to)3 4 defHanoi (N,SRC,TMP,DST):#move n plates from SRC to DST5     ifn = = 1:#there's only one plate in the case.6 Move (SRC,DST)7     Else:#There are more than one plate in the case8Hanoi (N-1,SRC,DST,TMP)#move the top n-1 tray from SRC to tmp9Move (SRC,DST)#easily and happily move the nth plate from SRC to DSTTenHanoi (N-1,TMP,SRC,DST)#wipe your butt and move the n-1 tray on TMP to DST . One  A  -Hanoi (3,'A','B','C')


Expected output:

1 #Expected output:2 #A -and C3 #A -and B4 #C --B5 #A -and C6 #B --A7 #B --C8 #A -and C9Move (3,'A','B','C')

python-Hanoi Recursive implementation

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.