re: Project Euler #2 - Even Fibonacci numbers VIEW POST

FULL DISCUSSION
 

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
}
code of conduct - report abuse