Solving the __python problem with Python

Source: Internet
Author: User

Although not the idea of how to do it, but feel the understanding of the problem is a step further, the previous use of Java to think for a long time to think very confused, or Python language concise, especially good understanding, as follows:


Topic:

Hanoi: Hanoi (also known as Heneta) is a puzzle toy from an ancient Indian legend. When the great Brahma created the world, he made three diamond pillars and stacked 64 gold discs on a pillar from the bottom up to the top in order of size. Brahma ordered the Brahman to rearrange the disc from below to another pillar in order of size. It is also stipulated that the disc cannot be enlarged on a small disc and only one disc can be moved between the three pillars at a time.


Solution:

def moves (n,a,b,c):
    if n==1:
    	print (A, '--> ', c)
    else:
    	Move (n-1,a,c,b)   #将前n-1 plates moving from A to B
    	Move (1,a,b,c)     #将最底下的最后一个盘子从a移动到c上
    	Moving (n-1,b,a,c)   #将b上的n-1 plates moved to C moves
(3, ' A ', ' B ', ' C ')




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.