-
Notifications
You must be signed in to change notification settings - Fork 2
/
DieHard.tla
46 lines (36 loc) · 1.17 KB
/
DieHard.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-------------------------------- MODULE test --------------------------------
EXTENDS Naturals, Integers, FiniteSets, Bags, Sequences, TLC
CONSTANTS Goal, Jugs, Capacity
ASSUME /\ Goal \in Nat
/\ Capacity \in [Jugs -> Nat \ {0}]
Min(m,n) == IF m < n THEN m ELSE n
Max(m,n) == IF m > n THEN m ELSE n
Foo == [x \in Nat, y \in Nat |-> x*y]
(*
--algorithm DieHard {
variables injug = [j \in Jugs |-> 0];
{
while(TRUE) {
either with(j \in Jugs) { \* Empty a jug
injug[j] := 0;
}
or with(j \in Jugs) { \* Fill a jug
injug[j] := Capacity[j];
}
\* Move water from j -> k
or with(j \in Jugs, k \in Jugs \ {j},
pour = Min(injug[j], Capacity[k] - injug[k])) {
injug[j] := injug[j] - pour || injug[k] := injug[k] + pour;
}
};
print [j \in Jugs |-> injug[j]];
}
}
*)
http://www.archimedes-lab.org/How_to_Solve/images/Water_gas_puzzle.gif
\* BEGIN TRANSLATION
\* END TRANSLATION
=============================================================================
\* Modification History
\* Last modified Thu Mar 19 12:34:13 CET 2015 by bela
\* Created Thu Mar 12 17:37:39 CET 2015 by bela