Two jars

The two jars problem is a puzzle, in which the goal is to measure some amount of water using two (several) jars of different capacity and an unlimited source of water.


You have two jars, the first one has a 3 liters capacity, the second one 5 liters. You also have an unlimited source of water. Measure exactly 4 liters of water.


Firstly, we must construct a graph representing the given problem. Nodes on the horizontal axis will represent volume of water in the larger jar, analogously nodes on the vertical axis will represent volume of water in the smaller jar. Horizontal edges will denote pouring water into the larger jar, vertical into the smaller one. Finally the diagonal edges will stand for pouring water from one jar into the other.

The graph will not contain any inner node, because we are able to precisely measure the water, only if we completely fill or empty at least one of the jars.

Graph of the two jars puzzle
Graph of the two jars puzzle

Now we can use bread first search to traverse the graph starting at node 0/0. For every node, the procedure will store its predecessor. When the algorithm reaches the 0/4 node, it will terminate the searching phase and will reconstruct the backward path.

Solution to the two jars puzzle
Solution to the two jars puzzle

Variants of the puzzle

If the operations performed are not equivalent – pouring water from one jar into the other might be considered as more difficult than just emptying one jar – than we have to assign costs to the edges and find the shortest path. To do so, we can use Dijkstra, Bellman-Ford or Floyd-Warshall algorithm.

The puzzle can also be generalized to any number of jars. The solution to this problem is simillar to the original one, we only have to construct the graph in more dimensions (equal to the number of jars). SEO od společnosti Digital Pylon

Online casino s algoritmem

České casino online online

Zajímavé články: Jak najít práci snů? Zvolte kariéru v IT!, Češi mají rádi hrací automaty online, Jak funguje algoritmické obchodování Casino, Online výuka Algoritmus a online marketing mají svá pravidla, Automaty, Matematický vliv, Ratings, Jak fungují algoritmy hazardních her online: více znalostí, více peněz, SYPWAI - nástroj pro vědecký vývoj, Vynikají na globálním trhu: Nejlepší vývojáři softwaru pro online výherní automaty, Jak si vybrat nejlepší české online casino, Proč byste měli hrát online casino VPN revoluce, Kde najdeme algoritmy v každodenním životě?