Artificial intelligent assistant

Is there any way to generalise this problem? My friend posed this question to me: I have a glass with 8 litres of water along with one empty 3 litre and an empty 5 litre glass. I have to pour 4 litres of water into his glass in one go. His glass is not calibrated. We do not know how much volume of water it can hold(but it is more than 4). I solved the problem in this way: $\begin{matrix} 8 & 0 &0 \\\ 3&5&0\\\ 3&2&3\\\ 6&2&0\\\ 6&0&2\\\ 1&5&2\\\ 1&4&3\\\ \end{matrix}$ Now I can pour the 4 litres from the 5 litre glass. My question is that can I generalise this problem? > If I have $V_1$ volume of water in a glass which has a capacity of $V_1$ along with 2 other glasses of volume $V_2$ and $V_3$ such that ($V_2$ and $V_3$ $\lt$ $V_1$).My friend needs $V$ volume of water in one go. And under what conditions will this generalisation fail?

There is an extended discussion of such problems and a graphical method of solution in Chapter $4$, ‘Bouncing Balls in Polygons and Polyhedrons’, of _Martin Gardner’s $6$th Book of Mathematical Diversions from ‘Scientific American’_. He says that the graphical method, which uses rhomboidal graphs on a grid of equilateral triangles, first appears in M.C.K. Tweedie, ‘A Graphical Method of Solving Tartaglian Measuring Puzzles’, _The Mathematical Gazette_ , Vol. $23$, No. $255$; July, $1939$, pp. $278$-$282$.

More accessible is the extensive discussion of the problem starting here at Alex Bogomolny’s Cut The Knot! site.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 1c9e9e206760eabf09755abd672eddb1