2010-06-23 23:03:09 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
// -*- rust -*-
|
2011-07-27 07:19:39 -05:00
|
|
|
fn ack(m: int, n: int) -> int {
|
|
|
|
if m == 0 {
|
2011-06-15 13:19:50 -05: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);
|
|
|
|
} else { ret ack(m - 1, ack(m, n - 1)); }
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2011-06-15 13:19:50 -05:00
|
|
|
assert (ack(0, 0) == 1);
|
|
|
|
assert (ack(3, 2) == 29);
|
|
|
|
assert (ack(3, 4) == 125);
|
|
|
|
// This takes a while; but a comparison may amuse: on win32 at least, the
|
|
|
|
// posted C version of the 'benchmark' running ack(4,1) overruns its stack
|
|
|
|
// segment and crashes. We just grow our stack (to 4mb) as we go.
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
// assert (ack(4,1) == 65533);
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
}
|