How to draw a graph that represent this problem? Using a $5$-liter bottle and a $3$-liter bottle to arrive at exactly $4$ liters of water.

183 Views Asked by At

You have 2 water bottles, a 5l bottle and a 3l bottle.

  • If the bottle is empty, You can fill it up fully at the tap.
  • If the bottle is full, You can empty the bottle.
  • You can transfer the content of one bottle to the other. Ex: if the 5l bottle has 3l of water and you put water from 5l bottle in the 3ml bottle, You will end up with 5l in the biggest and 1l in the smallest.
  • All bottles are empty.
  • Your goal is to obtain exactly 4l in the biggest bottle.
3

There are 3 best solutions below

0
On BEST ANSWER

Here is the graph representing the states of the puzzle and the possible ways we can get from one state to another.

A node labeled $(a,b)$ corresponds to a state where the $5$-liter bottle contains $a$ liters and the $3$-liter bottle contains $b$ liters. There are two kinds of edges:

  • Edges represented by solid lines describe two-way actions, where we can go from either state to the other. (For example, we can fill an empty bottle from the sink, then pour it out, returning to the original state.)
  • Edges represented by dashed lines describe one-way actions, which we cannot undo in one step. (For example, once we solve the puzzle, we can pour out the bottle with $4$ liters of water, and now we have to solve the puzzle all over again.)

This distinction is just to make the graph easier to read, avoiding too many arrows.

enter image description here

0
On

Here are the steps

$$1) \;\;B=0,b=3$$ $$2)\;\; B=3,b=0$$ $$3) \;\;B=3,b=3$$ $$4) \;\;B=5,b=1$$ $$5) \;\;B=0,b=1$$ $$6) \;\;B=1,b=0$$ $$7) \;\;B=1, b=3$$ $$8) \;\;B=4,b=0$$

0
On

I couldn't find an ideal graphical representation, but this is what I got:

attempt at graph