Example of a python puzzle game computing Tower

Source: Internet
Author: User

The quanta (also known as Hanoi) problem is originated from an ancient legend of India's educational toys. When I created the world, da fan Tian made three diamond pillars, stacked 64 gold disks from bottom to top in order of size. The great fan Tian command Brahman re-placed the disc from below in order of size on another pillar. 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.

Copy codeThe Code is as follows:
Times = 0
Def test (num, a, B, c ):
Globaltimes
Ifnum = 1:
Print (a, B)
Times + = 1

Else:
Test (num-1, a, c, B)
Test (1, a, B, c)
Test (num-1, c, B,)



Test (12, "a", "B", "c ")
Print "passing: % d" % times

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.