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

1.23 2.0 main test-branch
Last change on this file since b7a3ce6 was 0ae124a, checked in by Yihao Yan <yihaoyan1@…>, 10 years ago

format changes

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

  • Property mode set to 100644
File size: 808 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*/
11
12#include <civlc.cvh>
13
14$input int N_BOUND=4;
15$input int n;
16$input int x;
17$input int y;
18$input int X1[n];
19
20$assume (x < n && y < n && x >=0 && y>=0 && n > 0 && n <= N_BOUND);
21
22int lcp(int *arr, int n, int x, int y) {
23 int l=0;
24
25 while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) {
26 l++;
27 }
28 return l;
29}
30
31void main() {
32 int result = lcp(X1, n, x, y);
33
34 $assert($forall {i = 0 .. (result-1)} X1[x+i] == X1[y+i]);
35
36 int maxXY = x > y ? x : y;
37
38 if(result + maxXY < n) {
39 $assert(X1[x+result] != X1[y+result]);
40 }
41}
Note: See TracBrowser for help on using the repository browser.