Created
April 5, 2013 20:05
-
-
Save themasch/5322197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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