A simple iterative Rust Solution. Takes about 0.9 sec, and optimized one takes 0.35 sec
fn fibo(mut a: i64, mut b: i64, max: i64) -> i64 { let mut sum = 0; while a < max { if a % 2 == 0 { sum += a; } let c = a+b; a = b; b = c; } sum } fn main() { println!("{}", fibo(1,2,4000000)) // 4613732 }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A simple iterative Rust Solution.
Takes about 0.9 sec, and optimized one takes 0.35 sec