Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed task 082 #20

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion tasks/human_eval_082.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,39 @@ use vstd::prelude::*;

verus! {

// TODO: Put your solution (the specification, implementation, and proof) to the task here
pub open spec fn is_divisible(n: int, divisor: int) -> bool {
(n % divisor) == 0
}

pub open spec fn is_prime(n: int) -> bool {
if n < 2 {
false
} else {
(forall|k: int| 2 <= k < n ==> !is_divisible(n as int, k))
}
}

// Implementation following the ground-truth
// This function checks whether a given string length is prime
fn prime_length(str: &[char]) -> (result: bool)
ensures
result == is_prime(str.len() as int),
{
if str.len() < 2 {
return false;
}
for index in 2..str.len()
invariant
2 <= index <= str.len(),
forall|k: int| 2 <= k < index ==> !is_divisible(str.len() as int, k),
{
if ((str.len() % index) == 0) {
assert(is_divisible(str.len() as int, index as int));
return false;
}
}
true
}

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