rust/src/test/bench/shootout-fibo.rs
Marijn Haverbeke ffd50b9cdf Make the various from_str functions return options
So that they can be used with user input without causing task
failures.

Closes #1335
2012-02-22 13:18:15 +01:00

19 lines
305 B
Rust

use std;
fn fib(n: int) -> int {
if n < 2 {
ret 1;
} else {
ret fib(n - 1) + fib(n - 2);
}
}
fn main(args: [str]) {
let n = if vec::len(args) == 2u {
option::get(int::from_str(args[1]))
} else {
30
};
std::io::println(#fmt("%d\n", fib(n)));
}