JS realizes the cup pours water problem automatic solution Program _javascript Skill

Source: Internet
Author: User

Quiz questions often come up with similar logic questions, giving you a couple of cups of varying capacity to let you pour out how much water you have.

Android has a special game to play this topic called water Logic.


I install this game to dozens of levels pass again, feel the game design is not very good, the level of difficulty is not incremental, there are many behind the level of the mentally retarded, and the lack of difficult checkpoints.

As programmers, we should play such topics should be no problem, within 10 steps can easily be done, 10 steps or more can be done but may not be able to easily achieve the minimum number of steps.

Have 3 star obsessive-compulsive disorder player and programmer, write such an automatic solution of the small program, later this problem is no longer a problem.


Click here to try the cup water pouring problem automatically solve it

algorithm basic Logic :

Each cup is filled, emptied, poured into other cups operation, so the total is: Cup number * (number of cups -1+2)

For 3 cups, there are 12 different options for each step. If 2 cups have 6 kinds of optional operation each step.

Traverse each operation to record the amount of water in each cup after the operation is completed, and create a map by calculating a key to the amount of water.

The operation is discarded if the key already exists and the current step is greater than the number of previous records during the process of traversing a variety of inverted water operations.

This small program can only solve 2 cups or 3 cups of water pouring problem, and did not write N Cup general, the code has a lot of hard codes.

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.