Measuring With Jugs: A Solution in Finite Domain Charles R Ritchey, Jr., Russ Abbott, Eun-Young Kang ritcheyc@gmail.com, {rabbott, eykang}@calstatela.edu California State University, Los Angeles Department of Computer Science 5151 State University Dr. Los Angeles, CA 90032 USA Tel (323)445-2792 Fax (323)343-6672 Abstract The “measuring with jugs problem” involves pouring water between jugs to measure out a specific quantity of water. The object is to find the proper sequence of fill operations, pour operations (from one jug to another) and emptying operations to arrive at the desired quantity of water which may be in either jug. In the past, solutions to this puzzle have always involved creating a series of operations by computing various possible paths and choosing the one that leads to a solution. This paper takes a different, novel route to the solution to this. An answer is found numerically using constraint programming and the results are then translated into a path. At first, a simplified version of this puzzle using only two jugs will be discussed. A mathematical solution to this problem will be presented and the solution will then be translated into code in the Mozart-Oz programming language. Keywords: Constraint Programming, Mozart-Oz, Finite Domain 1. Introduction Mozart-Oz, more properly known as Oz3, is a multi-paradigm programming language. It may be used to create programs of many types and styles, i.e. many paradigms. Its main strength, though, is its ability to make short work of some rather complex programming problems using constraint programming. In standard logic programs, the computer must try multiple values for each variable until all values satisfy a set of conditions and a solution is reached. With constraint programming, however, the computer will solve a problem by taking a range of possible values for variables and narrowing their possible ranges based on constraints given by the programmer. The ranges of possible values are continually narrowed by the computer until a solution is found. This makes it excellent for finding the number of and type of operations necessary to solve this particular problem. 1.1 The Problem In this simple version, the challenge is that given 2 jugs, one must measure out an exact quantity of water. This may be any quantity which is less than the volume of the largest jug. In this problem, there is an unlimited supply of water available for filling either jug or both jugs. Also, when a jug is filled, it must be filled to capacity. Either or both may be emptied as often as desired and in any order desired. The object is to find the proper sequence of fill operations, pour operations (from one jug to another) and emptying operations to arrive at the desired quantity of water which may be in either jug. An example of this would be: given a 5 liter jug and a 3 liter jug, measure out 4 liters. A solution would be: Fill the 5 liter jug, pour 3 liters into the smaller jug filling it to capacity. Empty the smaller jug and pour the 2 liters remaining in the 5 liter jug into the 3 liter jug. Fill the 5 liter jug. Pour 1 liter from the 5 liter jug into the 3 liter jug (which already contains 2 liters) to fill it to capacity. There are now 4 liters of water in the large jug (and 3 liters in the smaller jug).