Jar to measure 6 liters

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
6) get 3 liters from second jar           4 liters left

how are you measuring 3 liters?
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.
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

>> 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.

I get it by filling first jar. It has volume 5liters. And 2 already in. So, only 3 liters could be added more.
gotcha,  thanks
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.
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.
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.)
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Puzzles / Riddles

From novice to tech pro — start learning today.