C # implement tower of Hanoi

Source: Internet
Author: User

The origins of the Tower:
Pandata is a toy derived from Indian mythology.
When God created the world, he made three diamond pillars and placed 64 gold disks in order from bottom to bottom.
God ordered the Brahman to re-place 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.
It was predicted that the universe would flash into destruction at the completion of the event. Some people believe that Brahman is still moving the disc for a moment.
Life Cycle tower and Universe:
If it takes one second to move a disc, when will the universe be destroyed when all the 64 discs fall together?
Let's consider how many times the 64 disks need to be moved. One time is of course one time, two times is three times, and three times is used seven times.
When one disc is created, the power of 2 is reduced by 1.
When two disks exist, the power of 2 is reduced by 1.
When three disks exist, the power of 2 is reduced by 1 to the power of 3.
When there are four disks, the power of 2 is reduced by 1 to the power of 4.
When there are five disks, the power of 2 is reduced by 1 to the power of 5.
........
When N disks exist, the Npower of 2 is reduced by 1.
That is to say, when n is 64, it is (the power of 2 is reduced by 1.
Therefore, it takes one second to move a disc,
The lifetime of the universe = the power 64 of 2 minus 1 (seconds)
It takes about 580 billion years for a year = 60 seconds x 60 Minutes x 24 hours X days.
It is said that the age of the universe is about 15 billion years.
The quanta issue has a high research value in the field of mathematics,
And it is still being studied by some mathematicians,
It is also a puzzle game that we like to play,
It can help develop intelligence and stimulate our thinking.
C language implementation of Linglong
# Include "stdio. H"
Void move (char X, char y)
{
Printf ("% C --> % C/N", x, y );
}
Void Hanoi (int n, char one, char two, char Three)
{
If (n = 1) Move (one, three );
Else {
Hanoi (n-1, one, three, two );
Move (one, three );
Hanoi (n-1, two, one, three );
}
}

 

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.