[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Jar to measure 6 liters

Posted on 2010-03-29
10
Medium Priority
?
1,549 Views
Last Modified: 2012-05-09
I have two Jars 5 liters and 7 liters and a well to take water.
I want to measure exact 6 liters with out using a 3rd jar.
Please help
0
Comment
Question by:PeteEngineer
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 12

Accepted Solution

by:
lazyberezovsky earned 2000 total points
ID: 28986421
Here your jars and steps :)
               5liters                                   7liters
1)    <empty>                                      fill 7 liters
2)   get 5 liters from second jar       2 liters left
3)   empty this jar                                2 liters
4)   get 2 liters from second jar           <empty>
5)  2 liters                                         fill 7 liters
6)  get 3 liters from second jar           4 liters left
7) empty this jar
8) get 4 liters from second jar            <empty>
9) 4 liters                                           fill 7 leters
10) get 1 liter from second jar           6 liters left BINGO!
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 28986681
6) get 3 liters from second jar           4 liters left


how are you measuring 3 liters?
0
 
LVL 33

Expert Comment

by:phoffric
ID: 28987093
If you have two jars having an integral number of liters, k and m, respectively, then if k and m are mutually prime (i.e., they share no prime factor other than 1), then you can ask for any amount of liters <= k. It may take a hundred steps (or a thousand) but it is doable.

When considering gcd, we know that for mutually prime numbers, k and m, gcd(k,m) = 1, and so there exists integers a, b such that ak + bm = 1.
This is the basis solving the above problem.
0
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
LVL 33

Expert Comment

by:phoffric
ID: 28987335
>> how are you measuring 3 liters?
Looks like he poured the 7 liters into the 5 liter jar (which already had 2 liters), and he filled the 5 liters to capacity; so 3 liters was removed from the 7 liters leaving only 4 liters in the 7 liter jar.
0
 
LVL 12

Expert Comment

by:lazyberezovsky
ID: 28987415
sdstuber,

I get it by filling first jar. It has volume 5liters. And 2 already in. So, only 3 liters could be added more.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 28987435
gotcha,  thanks
0
 
LVL 33

Expert Comment

by:phoffric
ID: 28987537
So, if I had a 27 liter jar (3^3) and a 64 liter jar, I should be able to measure any number of liters from 1 to 64.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 28990428
only consuming 20 liters total this way (instead of 21 for lazyberezovsky's approach) :

      5 liters            7 liters
1)      fill 5 liters            empty
2)      empty                  get 5 liters from first jar
3)      fill 5 liters            5 liters
4)      3 liters left            get 2 liters from first jar
5)      3 liters            empty this jar
6)      empty                  get 3 liters from first jar
7)      fill 5 liters            3 liters
8)      1 liter left            get 4 liters from first jar
9)      1 liter                  empty this jar
10)      empty                  get 1 liter from first jar
11)      fill 5 liters            1 liter
12)      empty                  get 5 liters from first jar
13)      empty                  6 liters

I'm all for preserving this precious resource lol ;)

Merely for fun - don't award points please.
0
 
LVL 33

Expert Comment

by:phoffric
ID: 28990869
Yes, there are two ways to solve the problem. One approach is to start off with the smaller jar being empty, and the other approach has the larger jar being empty. I don't know how to predict which approach reaches the goal faster. (I think I used to know.)
0
 
LVL 9

Expert Comment

by:jkunrein
ID: 33003033
Just to add to this fun little exercise...

You can solve these types of problems with a Diophantine equation.  For this problem, you write it as:
5x + 7y = 6

You assign the two known jars as coefficients of x and y, and you are setting it equal to the final value you want.  Any integer solution of x and y will tell you how many times you need to fill one jar and how many times you dump the other jar.

For example, you can see that (-3, 3) solves the equation. The -3 means that you dump out the x jar (in this case, 5 liters) three times and that you fill the y jar (7 liters) three times.  If you follow lazyberezovsky's solution, you see that's exactly what happened.  Well, the third dumping of the 5-liter jar was understood.  You actually have 11 liters between the two jars, but the dumping of the 5 liters is a given once you obtain your goal.

Also interesting is that there is more than one way to do this.  Notice that (4, -2) is another solution.  This means that you can get your 6 liters by filling up the 5-liter jar four times while dumping the 7-liter jar twice.  

And, as phoffric points out, this works best if the two jar values are relatively prime, but it also depends on whether the common factor is also a factor of the final value.  You can see more about it at: http://everything2.com/title/Two+water+jugs+problem

But, in short, you can write these problems out as ax + by = c.  If there is an integer solution for x and y then this can be solved. Technically, there are an infinite number of solutions, but most of them would just repeat the two most basic solutions.

Fun times.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally published Entrepreneur.com Booming numbers of freelancing professionals are changing the face of work. In the United States alone last year, the number of workers freelancing grew from 700,000 to 54 million, according to a Freelancers’…
Machine Learning is one of the profound applications of AI and therefore, just like AI, it is surrounded by myths and fears. Check out these facts about ML that demystify the related myths.
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question