aboutsummaryrefslogtreecommitdiff
path: root/src/test/bench/shootout/ackermann.rs
blob: 27b4c3c05a7b7bec18d7b515b38afdb144f05784 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// -*- rust -*-

fn ack(int m, int n) -> 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() {
  check (ack(0,0) == 1);
  check (ack(3,2) == 29);
  check (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.

  // check (ack(4,1) == 65533);
}