rust/benches/helpers/fibonacci_helper_iterative.rs

16 lines
215 B
Rust
Raw Normal View History

2016-05-30 07:05:50 -05:00
#[inline(never)]
pub fn main() {
assert_eq!(fib(10), 55);
}
fn fib(n: usize) -> usize {
let mut a = 0;
let mut b = 1;
for _ in 0..n {
let c = a;
a = b;
2022-06-04 10:55:36 -05:00
b += c;
2016-05-30 07:05:50 -05:00
}
a
}