source: CIVL/examples/verifyThisProblems/quantifiedComp.cvl@ adcb43a

1.23 2.0 main test-branch
Last change on this file since adcb43a 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: 873 bytes
Line 
1/*
2Author: Yihao
3
4Download LCP.zip from: http://fm2012.verifythis.org/challenges
5
6-----------------
7Problem description:
8
9This is a verifyThis problem in 2012.
10This task asks you to get the longest common prefix of
11two subStrings.
12
13-----------------
14Verification task:
15
16Implement a the lcp function which takes an array, its length and two indices as input
17and verify that it behaves as described.
18
19command: civl verify quantifiedComp.cvl
20
21result: the problem is solved
22*/
23
24#include <civlc.cvh>
25#include <assert.h>
26
27$input int n=3;
28$input int x;
29$input int y;
30$input int X1[n];
31
32$assume (x < n && y < n && x >=0 && y>=0);
33
34int lcp (int *arr, int n, int x, int y) {
35 int l=0;
36
37 while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) {
38 l++;
39 }
40 return l;
41}
42
43void main() {
44 int result = lcp(X1, n, x, y);
45
46 assert($forall {int i | i>=0 && i<result} X1[x+i] == X1[y+i]);
47}
Note: See TracBrowser for help on using the repository browser.