2 from random
import randint
7 ### On remplit le tableau "a"
9 for i
in range(0, len(a
)):
10 a
[i
] = randint(0, 100)
14 ### On prend une photo de "a"
19 #@ invariant 0 <= k <= len(a)
20 #@ invariant forall i. 0 <= i < k -> photo[i] == a[i]
25 #@ assert forall i. 0 <= i < len(a) -> photo[i] == a[i]
27 ### Et maintenant on le trie
31 #@ invariant 1 <= m <= len(a)
32 #@ invariant forall i,j. 0 <= i <= j < m -> a[i] <= a[j]
33 #@ invariant forall v. occurrence(v, a) == occurrence(v, photo)
37 while k
> 0 and a
[k
-1] > x
:
38 #@ invariant 0 <= k <= m
39 #@ invariant forall i,j. 0 <= i <= j < k -> a[i] <= a[j]
40 #@ invariant forall i,j. 0 <= i < k < j <= m -> a[i] <= a[j]
41 #@ invariant forall i,j. k < i <= j <= m -> a[i] <= a[j]
42 #@ invariant forall j. k < j <= m -> x < a[j]
43 #@ invariant forall v. occurrence(v, a[k <- x]) == occurrence(v, photo)
47 #@ assert occurrence(x, a[k <- x]) == occurrence(x, photo)
51 #@ assert forall i,j. 0 <= i <= j < len(a) -> a[i] <= a[j]
52 #@ assert forall v. occurrence(v, a) == occurrence(v, photo)