Last active
April 11, 2018 20:31
-
-
Save hwayne/92d65e81b4dbf5e08c334d695a7b41fd to your computer and use it in GitHub Desktop.
Dafny
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
method Unique(a: seq<int>) returns (b: seq<int>) | |
ensures forall k :: 0 <= k < |a| ==> a[k] in b | |
ensures forall i, j :: 0 <= i < j < |b| ==> b[i] != b[j] | |
{ | |
var index := 0; | |
b := []; | |
while index < |a| | |
invariant index <= |a| | |
invariant forall i, j :: 0 <= i < j < |b| ==> b[i] != b[j] | |
invariant forall k :: 0 <= k < index ==> a[k] in b | |
{ | |
if (a[index] !in b) { | |
b := b + [a[index]]; | |
} | |
assert a[index] in b; | |
index := index + 1; | |
} | |
return b; | |
} | |
//https://rise4fun.com/Dafny/3K7p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment