Datasets:
Download level_1/100.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/100.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/100.rs
-
curl -L -o 100.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/100.rs
1.1 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| spec fn f1_is_lower_case(c: u8) -> bool { | |
| c >= 97 && c <= 122 | |
| } | |
| spec fn f1_is_upper_case(c: u8) -> bool { | |
| c >= 65 && c <= 90 | |
| } | |
| spec fn f1_count_uppercase_recursively(seq: Seq<u8>) -> int | |
| decreases seq.len(), | |
| { | |
| if seq.len() == 0 { | |
| 0 | |
| } else { | |
| f1_count_uppercase_recursively(seq.drop_last()) + if f1_is_upper_case(seq.last()) { | |
| 1 as int | |
| } else { | |
| 0 as int | |
| } | |
| } | |
| } | |
| fn f1_count_uppercase(text: &[u8]) -> (count: u64) | |
| { | |
| let mut index = 0; | |
| let mut count = 0; | |
| while index < text.len() | |
| { | |
| if (text[index] >= 65 && text[index] <= 90) { | |
| count += 1; | |
| } | |
| index += 1; | |
| } | |
| count | |
| } | |
| spec fn step1(__hp0: Seq<u8>, outp: u64) -> bool { | |
| (0 <= outp <= __hp0.len()) | |
| && (f1_count_uppercase_recursively(__hp0) == outp) | |
| } | |
| fn chain_driver(text: &[u8]) -> (r_final: u64) | |
| ensures | |
| step1(text@, r_final), | |
| { | |
| let x1 = f1_count_uppercase(text); | |
| proof { | |
| assert(step1(text@, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |