The Snail climbs the wall

Source: Internet
Author: User

The Snail climbs the wall
A snail climbed 10 meters high wall, climb 3 meters in the morning, 2 meters at night, ask the snail how many days can climb over that 10 meters of the city wall?

Day one: 3 m
First night: Drop 2 m first day forward: 1 m
Day two: 1+3 m
Next night: Drop 2 m next day forward: 2 m
......
And finally boarded the 10-metre wall.

Data structure Analysis:
Initial height: high=0; height of snail Climb (change): int high;
Height of day climbing (unchanged): 3; height of the Night Drop (unchanged): 2;
Day crawl height (unchanged): 1;
Snail's height is equal to greater than 10 o'clock the day of success, that is, n days plus 3 is greater than or equal to 10 OK
Cycle: Crawl every day (use Do While loop, first operation again to judge, until the final result, but the number of cycles unknown)
Condition judgment: The height reaches 10 meters is the final condition

The game of the Snail climbing the wall: (the result is a little unexpected AH)
There is an old puzzle about snails climbing the wall. The topic is this:
There was a 11-foot-high, slippery brick wall, and a snail began to climb. It can climb 5 feet in one hours, but it will take an hour to rest after each climb. During the rest of the hour, it slipped down 3 feet. How many hours will the snail climb to the top of the wall?
The snail climbed to the top, and then it began to crawl from the other end, and it climbed 5 feet in one hours, but it rested for an hour after each climb. During the rest of the hour, it slipped down 3 feet. How long does it take for a snail to crawl from the other side of the wall that is slippery on both sides?
It's easy to say that since it actually climbs 2 feet every two hours, it will take 11 hours to climb a 11-foot wall.
Of course it's not right. Yes, it only climbed 6 feet after 6 hours, but after one hours it climbed 5 feet and sat on the wall for a total of 7 hours.
It takes 1 hours for the snail to climb down the wall.
Most people will say it takes 2.6 hours, but since the snail is going to slide 3 feet during the one-hour break, that means that if it stays on the wall for an hour, it will slide down 3 feet. So if it's a non-slip wall, it can climb 8 feet an hour instead of 5 feet. In the one-hour downward climb, if it climbs a smooth wall, it will also slide down 3 feet, so that the total 11 feet in an hour, which is precisely the height of our wall.

The Snail climbs the wall

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.