Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
competitive-programming
code-generation
specification-generation
proof-generation
verification
rust
License:
Download leetcode/lc1342/code_spec.rs from Gax-c/VeriContest_Lite: direct link, hf CLI and curl.
- Browser
- Download file 777 Bytes
-
https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1342/code_spec.rs
- Command line
-
hf download hf://datasets/Gax-c/VeriContest_Lite/leetcode/lc1342/code_spec.rs
-
curl -L -o code_spec.rs https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1342/code_spec.rs
777 Bytes
| use vstd::prelude::*; | |
| fn main() {} | |
| verus! { | |
| pub struct Solution; | |
| impl Solution { | |
| pub open spec fn spec_steps(n: int) -> int | |
| decreases n | |
| { | |
| if n <= 0 { | |
| 0 | |
| } else if n % 2 == 0 { | |
| 1 + Self::spec_steps(n / 2) | |
| } else { | |
| 1 + Self::spec_steps(n - 1) | |
| } | |
| } | |
| pub fn number_of_steps(num: i32) -> (result: i32) | |
| requires | |
| 0 <= num <= 1_000_000, | |
| ensures | |
| result == Self::spec_steps(num as int), | |
| { | |
| let mut n = num; | |
| let mut steps = 0i32; | |
| while n > 0 { | |
| if n % 2 == 0 { | |
| n = n / 2; | |
| } else { | |
| n = n - 1; | |
| } | |
| steps = steps + 1; | |
| } | |
| steps | |
| } | |
| } | |
| } | |