Solving the Three Jugs Problem: A Precise Formulation and Algorithmic Approach