The problem with a jug of water in Die Hard 3 in the graph

im not too sure how to implement this ...

I need to create a weighted oriented graph based on the problem of a water jug ​​from the movie Die Hard 3 ( http://www.wikihow.com/Solve-the-Water-Jug-Riddle-from-Die-Hard-3 ).

I need to create nodes for all possible moves (fill, empty, pour). After I need to find the shortest path to a solution. But it’s hard for me to create this schedule. I use my own created linked list / node.

Any help with the algorithm to create this graph would be great. Thanks.

ex) given 3 gallons, 5 gallons. Get 4 gallons in a 5 gallon jug. I need to create a graph of all the possible steps to get to 4 gallons. Each other gallon is a different node.

Happy Thanksgiving =)

+3
source share
2 answers

, node - 3- , 5 . , (), "" ( , ) - -, , ; ( ); .. ( , , ). , , ( "" ), "" (, , ), , .

, (0, 0) - , . , (3, 0) (0, 5) ( ) .. , !

+3

6

1. =
2 =
3.A- > B
4.B- >
5.A = 0
6 = 0

. , . .

- A * B, - A * vol (B) + B

[A * vol (B) + B] , . -1 ( , 0 )

+2

Source: https://habr.com/ru/post/1724062/


All Articles