source: CIVL/examples/verifyThis/quantifiedComp.cvl@ 397ae5f

main test-branch
Last change on this file since 397ae5f was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 1.1 KB
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:
22For arrays with length less than 5, lcp function returns an integer n which is
23the length of the longest common prefix between its two suffixes: The two suffixes
24are the same with indexes from 0 to n-1 while they are different at index n.
25*/
26
27#include <civlc.cvh>
28#include <assert.h>
29
30$input int n=3;
31$input int x;
32$input int y;
33$input int X1[n];
34
35$assume (x < n && y < n && x >=0 && y>=0);
36
37int lcp (int *arr, int n, int x, int y) {
38 int l=0;
39
40 while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) {
41 l++;
42 }
43 return l;
44}
45
46void main() {
47 int result = lcp(X1, n, x, y);
48
49 assert($forall (int i: 0 .. result-1) X1[x+i] == X1[y+i]);
50}
Note: See TracBrowser for help on using the repository browser.