2012-01-14 21:38:28 -06:00
|
|
|
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 {
|
2012-01-14 21:38:28 -06:00
|
|
|
ret n + 1
|
2010-06-23 23:03:09 -05:00
|
|
|
} else {
|
2011-07-27 07:19:39 -05:00
|
|
|
if n == 0 {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret ack(m - 1, 1);
|
2012-01-14 21:38:28 -06:00
|
|
|
} else {
|
|
|
|
ret ack(m - 1, ack(m, n - 1));
|
|
|
|
}
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn main(args: ~[str]) {
|
2012-05-24 00:53:50 -05:00
|
|
|
let args = if os::getenv("RUST_BENCH").is_some() {
|
2012-06-29 18:26:56 -05:00
|
|
|
~["", "12"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} else if args.len() <= 1u {
|
2012-06-29 18:26:56 -05:00
|
|
|
~["", "8"]
|
2012-01-14 21:38:28 -06:00
|
|
|
} else {
|
2012-05-24 00:53:50 -05:00
|
|
|
args
|
2012-01-14 21:38:28 -06:00
|
|
|
};
|
2012-05-24 00:53:50 -05:00
|
|
|
let n = int::from_str(args[1]).get();
|
2012-03-12 22:04:27 -05:00
|
|
|
io::println(#fmt("Ack(3,%d): %d\n", n, ack(3, n)));
|
2011-08-19 17:16:48 -05:00
|
|
|
}
|