source: CIVL/examples/verifyThisProblems/lcp.c@ e769359

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

formating lcp.c

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

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