source:
CIVL/examples/verifyThis/quantifiedComp.cvl@
bb03188
| Last change on this file since bb03188 was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 1.1 KB | |
| Rev | Line | |
|---|---|---|
| [cc283ee] | 1 | /* |
| [41eb9b6] | 2 | Author: Yihao |
| [f3368e99] | 3 | |
| [41eb9b6] | 4 | Download LCP.zip from: http://fm2012.verifythis.org/challenges |
| 5 | ||
| 6 | ----------------- | |
| 7 | Problem description: | |
| [f3368e99] | 8 | |
| [cc283ee] | 9 | This is a verifyThis problem in 2012. |
| [f3368e99] | 10 | This task asks you to get the longest common prefix of |
| [cc283ee] | 11 | two subStrings. |
| 12 | ||
| [41eb9b6] | 13 | ----------------- |
| 14 | Verification task: | |
| 15 | ||
| 16 | Implement a the lcp function which takes an array, its length and two indices as input | |
| 17 | and verify that it behaves as described. | |
| [f7e5282] | 18 | |
| 19 | command: civl verify quantifiedComp.cvl | |
| 20 | ||
| [76f18de] | 21 | result: |
| 22 | For arrays with length less than 5, lcp function returns an integer n which is | |
| 23 | the length of the longest common prefix between its two suffixes: The two suffixes | |
| 24 | are the same with indexes from 0 to n-1 while they are different at index n. | |
| [cc283ee] | 25 | */ |
| 26 | ||
| 27 | #include <civlc.cvh> | |
| 28 | #include <assert.h> | |
| 29 | ||
| 30 | $input int n=3; | |
| 31 | $input int x; | |
| 32 | $input int y; | |
| 33 | $input int X1[n]; | |
| 34 | ||
| 35 | $assume (x < n && y < n && x >=0 && y>=0); | |
| 36 | ||
| [0ae124a] | 37 | int lcp (int *arr, int n, int x, int y) { |
| [cc283ee] | 38 | int l=0; |
| [f3368e99] | 39 | |
| [cc283ee] | 40 | while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) { |
| 41 | l++; | |
| 42 | } | |
| 43 | return l; | |
| 44 | } | |
| 45 | ||
| [0ae124a] | 46 | void main() { |
| [cc283ee] | 47 | int result = lcp(X1, n, x, y); |
| [f3368e99] | 48 | |
| [5cd8c92] | 49 | assert($forall (int i: 0 .. result-1) X1[x+i] == X1[y+i]); |
| [cc283ee] | 50 | } |
Note:
See TracBrowser
for help on using the repository browser.
