AI Experiment2
AI Experiment2
•Operators
if x < 4
if y < 3
if x > 0
if y > 0
if x > 0
if y >0
. 7. (x, y) ----->(4, y -(4 - x))
if x + y >= 4, y > 0 pour water from the 3- gallon jug into the 4-gallon jug until the 4-gallon jug is full
if x + y >= 3, x > 0 ) pour water from the 4- gallon jug into the 3-gallon jug until the 3-gallon is full
9. (x, y) ----->(x + y, 0)
if x + y <= 4, y > 0 pour all the water from the 3-gallon jug into the 4-gallon jug
if x + y <= 3, x > 0 pour all the water from the 4-gallon jug into the 3-gallon jug
11. (0, 2) ----->(2, 0) pour the 2 gallons from the 3-gallon jug into the 4-gallon jug
12. (2, y) ----->(0, y) empty the 2 gallons in the 4 gallon jug on the ground \
Code:
# before or not
m = {}
isSolvable = False
path = []
q = deque()
q.append((0, 0))
# Current state
u = q.popleft()
continue
path.append([u[0], u[1]])
m[(u[0], u[1])] = 1
isSolvable = True
if (u[0] == target):
if (u[1] != 0):
path.append([u[0], 0])
else:
if (u[0] != 0):
path.append([0, u[1]])
sz = len(path)
for i in range(sz):
path[i][1], ")")
break
c = u[0] + ap
d = u[1] - ap
q.append([c, d])
c = u[0] - ap
d = u[1] + ap
q.append([c, d])
# Empty Jug2
q.append([a, 0])
# Empty Jug1
q.append([0, b])
if (not isSolvable):
print("No solution")
# Driver code
if __name__ == '__main__':
Output: