Loading RustViz Engine...
Compute the nth Fibonacci number in O(1) space avoiding heap allocations.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn fib(n: u32) -> u64 {
if n == 0 { return 0; }
let mut a: u64 = 0;
let mut b: u64 = 1;
for _ in 1..n {
let next = a + b;
a = b;
b = next;
}
b
}