source: CIVL/examples/verifyThisProblems/lcp.c@ 7ea52ed

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 7ea52ed was 260762f, checked in by Yihao Yan <yihaoyan1@…>, 10 years ago

verify this problems

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@3060 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 729 bytes
Line 
1#include <civlc.cvh>
2
3/*
4Longest Common Prefix (LCP)
5Input: an integer array X1[n], and two indices x and y into this array
6Output: length of the longest common prefix of the subarrays of a
7 starting at x and y respectively.
8*/
9$input int N_BOUND=4;
10$input int n;
11$input int x;
12$input int y;
13$input int X1[n];
14
15$assume (x < n && y < n && x >=0 && y>=0 && n > 0 && n <= N_BOUND);
16
17int lcp(int *arr, int n, int x, int y){
18 int l=0;
19 while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) {
20 l++;
21 }
22 return l;
23}
24
25void main(){
26 int result = lcp(X1, n, x, y);
27 $assert($forall {i = 0 .. (result-1)} X1[x+i] == X1[y+i]);
28 int maxXY = x > y ? x : y;
29 if(result + maxXY < n){
30 $assert(X1[x+result] != X1[y+result]);
31 }
32}
Note: See TracBrowser for help on using the repository browser.