2012-09-11 17:46:20 -07:00
|
|
|
extern mod std;
|
2010-06-23 21:03:09 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
fn ack(m: int, n: int) -> int {
|
|
|
|
if m == 0 {
|
2012-08-01 17:30:05 -07:00
|
|
|
return n + 1
|
2010-06-23 21:03:09 -07:00
|
|
|
} else {
|
2011-07-27 14:19:39 +02:00
|
|
|
if n == 0 {
|
2012-08-01 17:30:05 -07:00
|
|
|
return ack(m - 1, 1);
|
2012-01-14 19:38:28 -08:00
|
|
|
} else {
|
2012-08-01 17:30:05 -07:00
|
|
|
return ack(m - 1, ack(m, n - 1));
|
2012-01-14 19:38:28 -08:00
|
|
|
}
|
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() {
|
|
|
|
~[~"", ~"12"]
|
2012-05-23 22:53:50 -07:00
|
|
|
} else if args.len() <= 1u {
|
2012-07-13 22:57:48 -07:00
|
|
|
~[~"", ~"8"]
|
2012-01-14 19:38:28 -08:00
|
|
|
} else {
|
2012-05-23 22:53:50 -07:00
|
|
|
args
|
2012-01-14 19:38:28 -08:00
|
|
|
};
|
2012-05-23 22:53:50 -07:00
|
|
|
let n = int::from_str(args[1]).get();
|
2012-08-22 17:24:52 -07:00
|
|
|
io::println(fmt!("Ack(3,%d): %d\n", n, ack(3, n)));
|
2011-08-19 15:16:48 -07:00
|
|
|
}
|