source: CIVL/examples/verifyThisProblems/lcp.c@ 315d1ee

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

format changing

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

  • Property mode set to 100644
File size: 1021 bytes
RevLine 
[260762f]1/*
[41eb9b6]2Author: Yihao
[c245979]3
[41eb9b6]4Download LCP.zip from: http://fm2012.verifythis.org/challenges
5
6-----------------
7Problem decription:
[c245979]8
[260762f]9Longest Common Prefix (LCP)
10Input: an integer array X1[n], and two indices x and y into this array
11Output: length of the longest common prefix of the subarrays of a
12 starting at x and y respectively.
[f7e5282]13
[41eb9b6]14-----------------
15Verification task:
[f7e5282]16
[41eb9b6]17Implement the lcp function, and verify that it behaves in the way described above.
18
[f7e5282]19result: the problem is solved
[260762f]20*/
[f3368e99]21
22#include <civlc.cvh>
23
[260762f]24$input int N_BOUND=4;
25$input int n;
26$input int x;
27$input int y;
28$input int X1[n];
29
30$assume (x < n && y < n && x >=0 && y>=0 && n > 0 && n <= N_BOUND);
31
[41eb9b6]32int lcp(int *arr, int n, int x, int y){
[260762f]33 int l=0;
[c245979]34
[260762f]35 while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) {
36 l++;
37 }
38 return l;
39}
40
[41eb9b6]41void main(){
[260762f]42 int result = lcp(X1, n, x, y);
[c245979]43
[260762f]44 $assert($forall {i = 0 .. (result-1)} X1[x+i] == X1[y+i]);
[c245979]45
[260762f]46 int maxXY = x > y ? x : y;
[c245979]47
[41eb9b6]48 if(result + maxXY < n){
[260762f]49 $assert(X1[x+result] != X1[y+result]);
50 }
51}
Note: See TracBrowser for help on using the repository browser.