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
RevLine 
[260762f]1/*
[0ae124a]2author: Yihao
[c245979]3
4Link(LCP.zip): http://fm2012.verifythis.org/challenges
5
[260762f]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.
[f7e5282]10
11command: civl verify lcp.c
12
13result: the problem is solved
[260762f]14*/
[f3368e99]15
16#include <civlc.cvh>
17
[260762f]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
[0ae124a]26int lcp(int *arr, int n, int x, int y) {
[260762f]27 int l=0;
[c245979]28
[260762f]29 while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) {
30 l++;
31 }
32 return l;
33}
34
[0ae124a]35void main() {
[260762f]36 int result = lcp(X1, n, x, y);
[c245979]37
[260762f]38 $assert($forall {i = 0 .. (result-1)} X1[x+i] == X1[y+i]);
[c245979]39
[260762f]40 int maxXY = x > y ? x : y;
[c245979]41
[0ae124a]42 if(result + maxXY < n) {
[260762f]43 $assert(X1[x+result] != X1[y+result]);
44 }
45}
Note: See TracBrowser for help on using the repository browser.