source: CIVL/examples/verifyThisProblems/lcp.c@ 0e12c94

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

minor changes

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

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