Question: Consider the following problem: You have a four - gallon jug and a three - gallon jug, neither of which has any markings. Understand what
Consider the following problem:
You have a fourgallon jug and a threegallon jug, neither of which has any markings. Understand what this means. The only reliable observations
are: a jug is empty in which case it has zero gallons in it; or a jug is full, in which case it has its "capacity" gallons in it and any other conclusions
you can logically draw from these states. For example, say you fill the gallon jug, and then fill the gallon jug from it you can logically conclude
that there is gallon left in the gallon jug. Since the jugs have no markings, no other amounts can be transferred from the full
gallon jug to the gallon jug. In this example, you cannot transfer or or or or gallons of water from the
gallon jug to the gallon jug.
There is a faucet from which you can top off the jug s as many times as you wish. Following this, a jug has its "capacity" gallons in it
You can empty one jug into the other, or onto the ground, in which case the jug is known to have zero gallons in it
You can transfer water between the two jugs. Again, since the jugs have no markings, the only transfers that are logical are those that leave one
jug full or the other empty.
Write a Prolog program that finds a sequence of moves in the form of a list of instructions that, starting from two empty.jugs, ends with exactly
two gallons of water in the gallon jug and no water in the gallon jug.
Use the below outline to solve the code:
ab represents a problem state with a gallons in the gallon jug
and b gallons in the gallon jug
You can fill the gallon jug from the faucet, taking you from a
problem state XY to a problem state Y
provided X
moveXY'Top off gallon jug from faucet',Y : X
Rule corresponding to the move 'Top off gallon jug from faucet'
moveXY'Top off gallon jug from faucet',X : Y
Rule corresponding to the move 'Empty gallon jug onto the ground'
Rule corresponding to the move 'Empty gallon jug onto the ground'
Rule corresponding to the move 'Top off gallon jug from gallon
jug'
Rule corresponding to the move 'Top off gallon jug from gallon
jug'
Rule corresponding to the move 'Empty gallon jug into gallon jug'
Rule corresponding to the move 'Empty gallon jug into gallon jug'
solution predicates
To solve the problem try this: lengthX Y Y solution X
is the goal state. No move required if you are in this state
solution
The list of moves MoveRest constitutes a solution from PresentState
if Move takes you from PresentState to NextState
and Rest represents a sequence of moves that will take
you from NextState to the goal state.
solutionPresentStateMoveRest : movePresentStateMove,NextState
solutionNextStateRest
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
