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

23 lines
412 B
Rust
Raw Normal View History

use std;
2010-06-23 23:03:09 -05:00
2011-07-27 07:19:39 -05:00
fn ack(m: int, n: int) -> int {
if m == 0 {
ret n + 1
2010-06-23 23:03:09 -05:00
} else {
2011-07-27 07:19:39 -05:00
if n == 0 {
ret ack(m - 1, 1);
} else {
ret ack(m - 1, ack(m, n - 1));
}
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 {
8
};
io::println(#fmt("Ack(3,%d): %d\n", n, ack(3, n)));
}