rust/src/test/bench/shootout-ackermann.rs
Brian Anderson 518dc52f85 Reformat
This changes the indexing syntax from .() to [], the vector syntax from ~[] to
[] and the extension syntax from #fmt() to #fmt[]
2011-08-20 11:04:00 -07:00

26 lines
577 B
Rust

// -*- rust -*-
fn ack(m: int, n: int) -> int {
if m == 0 {
ret n + 1;
} else {
if n == 0 {
ret ack(m - 1, 1);
} else { ret ack(m - 1, ack(m, n - 1)); }
}
}
fn main() {
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.
// assert (ack(4,1) == 65533);
}