Professional Documents
Culture Documents
Gries - Ch.10
Gries - Ch.10
guard
B: Boolean expression
S: command
B → S: guarded command
$ python3 gries_10_4.py 20
b = [-10, 60, -10, 40, -50, 30, -80, -10, -30, -10, 80, -40, 80, -60,
80, -50, 30, 80, 30, 50]
i = 5
p = 2
Postcondition is established
if (B1) S1;
No defaults!
The possibility of nondeterminism!
$ python3 max_nondet_v1.py 15 7
max = 15 is from a, branch 1 (baab)
$ python3 max_nondet_v1.py 15 7
max = 15 is from a, branch 1 (abba)
$ python3 max_nondet_v1.py 17 17
max = 17 is from a, branch 1 (abba)
$ python3 max_nondet_v1.py 17 17
max = 17 is from b, branch 2 (baab)
$ python3 max_nondet_v2.py 44 44
The maximum of a(44) and b(44) = 44 by branch 1
$ python3 max_nondet_v2.py 44 44
The maximum of a(44) and b(44) = 44 by branch 2
0 i k j n
b x