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:
File size: 777 Bytes
4c0e24e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 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
}
}
}
|