# do you know this water jug problem

This topic is 4208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

you have two jugs,3 gallon one and 4 gallon one ,doesn't have any markers on it,you fill this jugs with pump,how to fill 2 gallons of water in 4 gallon jug? anybody know answer plz reply..

##### Share on other sites
What does this have to do with artificial intelligence?
I've heard variations of this puzzle before.
Interestingly (is that a word?), I don't think ai would have much trouble solving this problem (genetic algorithms/minimax would solve this easily).

1st solution: Fill the 3 gallon jug, and pour it into the 4 gallon jug.
Fill the 3 gallon jug again and begin pouring it into the 4 gallon jug but stop when the 4 gallon jug is full.

There is another solution but it's not perfect because it depends on the dimensions and mass of the jugs:

Fill the 4 gallon jug and pour it into the 3 gallon jug till there is one gallon left. Empty the 3 gallon jug, and pour the 1 gallon into it.
Fully fill the 4 gallon jug, then submerge the 3 gallon jug in it so the tops are level - it will displace roughly 3 gallons and there will be 1 gallon left in the large jug. Step 3: Profit!

Edit: Just thought of another solution:

Fill the 4 gallon jug and pour it into the 3 gallon jug till there is one gallon left. Empty the 3 gallon jug, and pour the 1 gallon into it.
Fully fill the 4 gallon jug, then pour it into the 3 gallon jug till it is full. There is now 2 gallons left.

##### Share on other sites
Quote:
 Original post by stevenmarkyWhat does this have to do with artificial intelligence?I've heard variations of this puzzle before.Interestingly (is that a word?), I don't think ai would have much trouble solving this problem (genetic algorithms/minimax would solve this easily).

Why? Why? whyyyyyy would you use genetic algorithms to solve a problem like that? Strong basics, guys. Even minimax is innapropriate. Simple state representation, very few actions possible, no good scoring/heuristic possible, solution is very short: this is the job for a simple breadth-first search.

##### Share on other sites
Quote:
 Original post by SteadtlerWhy? Why? whyyyyyy would you use genetic algorithms to solve a problem like that? Strong basics, guys. Even minimax is innapropriate. Simple state representation, very few actions possible, no good scoring/heuristic possible, solution is very short: this is the job for a simple breadth-first search.

That's my opinion too. If you prefer solutions that don't waste a lot of water, use Dijkstra's algorithm (very similar to breadth-first search).

##### Share on other sites
Quote:
 Original post by SteadtlerWhy? Why? whyyyyyy would you use genetic algorithms to solve a problem like that? Strong basics, guys. Even minimax is innapropriate. Simple state representation, very few actions possible, no good scoring/heuristic possible, solution is very short: this is the job for a simple breadth-first search.

You're right, GAs aren't appropriate for this. So I guess NNs must be the way to go. [grin]

##### Share on other sites
Die Hard 3, FTW.

I've had this come up in school, during an interview, and even as a puzzle in a D&D campaign. There's really no trick to it, just brute force your way to a solution. Either way you go (which jug you start with, I mean) will get you there.

##### Share on other sites
Quote:
 Original post by CyberSlag5kDie Hard 3, FTW.I've had this come up in school, during an interview, and even as a puzzle in a D&D campaign. There's really no trick to it, just brute force your way to a solution. Either way you go (which jug you start with, I mean) will get you there.

Wow. Im no big fan of puzzle questions in interviews, I would avoid like the plague any business that ask such a cliché puzzle.

Cheers to Sneftel who is trying to raise my temper :P

##### Share on other sites
I guess I just meant any brutish force algorithm would solve this easily.
Quote:
 Why didn't you say that then?

Shutup!
Well anyway, I have a generic minimax algorithm which could be applied to this problem easily (you could also set the amount of players, in this case it would be one).

##### Share on other sites
Quote:
Original post by stevenmarky
I guess I just meant any brutish force algorithm would solve this easily.
Quote:
 Why didn't you say that then?

Shutup!
Well anyway, I have a generic minimax algorithm which could be applied to this problem easily (you could also set the amount of players, in this case it would be one).

How would you score each "board" for minimax? Quantity of water in each jug is no indication of or close you are to "winning"

##### Share on other sites
I could just score 1 if either bucket contained the right amount of water.

• 11
• 20
• 12
• 10
• 38
• ### Forum Statistics

• Total Topics
631401
• Total Posts
2999864
×