Skip to content

Commit

Permalink
task 12
Browse files Browse the repository at this point in the history
  • Loading branch information
WeetHet committed Sep 17, 2024
1 parent 5eea4f9 commit 9f555fe
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tasks/human_eval_012.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,42 @@ use vstd::prelude::*;

verus! {

// TODO: Put your solution (the specification, implementation, and proof) to the task here
fn longest(strings: &Vec<Vec<u8>>) -> (result: Option<&Vec<u8>>)
ensures
match result {
None => strings.len() == 0,
Some(s) => {
forall|i: int|
#![auto]
0 <= i < strings.len() ==> s.len() >= strings[i].len() && exists|i: int|
#![auto]
(0 <= i < strings.len() && s == strings[i] && (forall|j: int|
#![auto]
0 <= j < i ==> strings[j].len() < s.len()))
},
},
{
if strings.len() == 0 {
return None;
}
let mut result: &Vec<u8> = &strings[0];
let mut pos = 0;

for i in 1..strings.len()
invariant
0 <= pos < i,
result == &strings[pos as int],
exists|i: int| 0 <= i < strings.len() && strings[i] == result,
forall|j: int| #![auto] 0 <= j < i ==> strings[j].len() <= result.len(),
forall|j: int| #![auto] 0 <= j < pos ==> strings[j].len() < result.len(),
{
if result.len() < strings[i].len() {
result = &strings[i];
pos = i;
}
}
Some(result)
}

} // verus!
fn main() {}
Expand Down

0 comments on commit 9f555fe

Please sign in to comment.