Skip to content

Instantly share code, notes, and snippets.

@themasch
Created April 5, 2013 20:05
Show Gist options
  • Select an option

  • Save themasch/5322197 to your computer and use it in GitHub Desktop.

Select an option

Save themasch/5322197 to your computer and use it in GitHub Desktop.
fn fibbo(max: int, cb: fn(int) -> bool) {
let mut a = 1;
let mut b = 0;
let mut c;
loop {
c = a;
a = a+b;
b = c;
if a > max {
break;
}
cb(a);
}
}
fn do_euler_02(max: int) -> int {
let mut result = 0;
for fibbo(max) | i | {
if i % 2 == 0 {
result += i;
}
}
return result;
}
fn main() {
let result = do_euler_02(4000000);
io::println(fmt!("%d", result));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment