fork download
  1. import fractions
  2.  
  3. class WaterJug:
  4.  
  5. def __init__(self, x, y, goal):
  6. self.JUG_1 = x
  7. self.JUG_2 = y
  8. self.j_1 = 0
  9. self.j_2 = 0
  10. self.pre_j_1 = 0
  11. self.pre_j_2 = 0
  12. self.goal = goal
  13. self.path = []
  14.  
  15. def get_path(self):
  16. pass
  17.  
  18. def next_state(self, next_act):
  19. self.path.append(self.j_1, self.j_2)
  20. if self.j_1 < self.JUG_1:
  21. next_act.append(self.JUG_1, self.j_2)
  22.  
  23. if self.j_2 < self.JUG_2:
  24. next_act.append(self.j_1, self.JUG_2)
  25.  
  26. if self.j_1 > 0:
  27. next_act.append(0, self.j_2)
  28.  
  29. if self.j_2 > 0:
  30. next_act.append(self.j_1, 0)
  31.  
  32. if self.j_1 + self.j_2 >= self.JUG_1 and self.j_2 > 0:
  33. next_act.append(self.JUG_1, self.j_2 - (self.JUG_1 - self.j_1))
  34.  
  35. if self.j_1 + self.j_2 >= 0 and self.j_1 > 0:
  36. next_act.append(self.j_1- (self.JUG_2 - self.j_2), self.JUG_2)
  37.  
  38. if self.j_1 + self.j_2 <= self.JUG_1 and self.j_2 > 0:
  39. next_act.append(self.j_1 + self.j_2, 0)
  40.  
  41. if self.j_1 + self.j_2 <= self.JUG_2 and self.j_1 > 0:
  42. next_act.append(0, self.j_1 + self.j_2)
  43.  
  44. if __name__ == "__main__":
  45. x = int(raw_input( "Enter the capacity of first Water jug : "))
  46. y = int(raw_input("Enter the Capacity of the second water jug : "))
  47. goal = int(raw_input("Enter the amount you want in the first jug : "))
  48. problem = WaterJug(x, y, goal)
  49. hcf = fractions.gcd( problem.JUG_1, problem.JUG_2)
  50. if goal % hcf == 0:
  51. problem.get_path()
  52. else: print "No Solution exists"
Runtime error #stdin #stdout #stderr 0.01s 24624KB
stdin
Standard input is empty
stdout
Enter the capacity of first Water jug : 
stderr
Traceback (most recent call last):
  File "prog.py", line 45, in <module>
EOFError: EOF when reading a line