rust/src/test/bench/shootout-fibo.rs

19 lines
300 B
Rust
Raw Normal View History

use std;
2011-07-27 07:19:39 -05:00
fn fib(n: int) -> int {
if n < 2 {
ret 1;
} else {
ret fib(n - 1) + fib(n - 2);
}
2010-06-23 23:03:09 -05:00
}
fn main(args: [str]) {
let n = if vec::len(args) == 2u {
option::get(int::from_str(args[1]))
} else {
30
};
io::println(#fmt("%d\n", fib(n)));
}