2012-01-14 19:00:59 -08:00
|
|
|
use std;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
fn fib(n: int) -> int {
|
2012-01-14 19:00:59 -08:00
|
|
|
if n < 2 {
|
|
|
|
ret 1;
|
|
|
|
} else {
|
|
|
|
ret fib(n - 1) + fib(n - 2);
|
|
|
|
}
|
2010-06-23 21:03:09 -07:00
|
|
|
}
|
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
fn main(args: ~[~str]) {
|
|
|
|
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
|
|
|
~[~"", ~"40"]
|
2012-05-23 22:53:50 -07:00
|
|
|
} else if args.len() <= 1u {
|
2012-07-13 22:57:48 -07:00
|
|
|
~[~"", ~"30"]
|
2012-01-14 19:00:59 -08:00
|
|
|
} else {
|
2012-05-23 22:53:50 -07:00
|
|
|
args
|
2012-01-14 19:00:59 -08:00
|
|
|
};
|
2012-05-23 22:53:50 -07:00
|
|
|
let n = int::from_str(args[1]).get();
|
2012-07-30 16:01:07 -07:00
|
|
|
io::println(fmt!{"%d\n", fib(n)});
|
2011-08-19 15:16:48 -07:00
|
|
|
}
|