(* Water jug problem -- for testing *) (* Printing functions for printing the state and lists of pairs of states. *) let print_wj (x,y) = Printf.printf "( %d, %d ) " x y ;; (* let print_dlist = List.iter (function (x,y) -> print_wj x; print_wj y) ;; *) let eq_wj (x,y) (z,t) = x=z && y=t let rule (x,y) = [ (x,0); (0,y); (x,3); (4,y) ] @ ( let a = min (4-x) y in if a > 0 then [ (x+a,y-a) ] else [] ) @ ( let a = min x (3-y) in if a > 0 then [ (x-a,y+a) ] else [] ) ;; let goal x= x = (2,0);; (* Searching *) List.iter print_wj (Bfsearch.bfsearch (0,0) goal rule eq_wj) ;; print_newline();;