Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 25 lines (19 sloc) 0.576 kb
d6b7c96 @graydon Populate tree.
graydon authored
1
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
2
3
4 // -*- rust -*-
df7f21d @marijnh Reformat for new syntax
marijnh authored
5 fn ack(m: int, n: int) -> int {
6 if m == 0 {
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
7 ret n + 1;
d6b7c96 @graydon Populate tree.
graydon authored
8 } else {
df7f21d @marijnh Reformat for new syntax
marijnh authored
9 if n == 0 {
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
10 ret ack(m - 1, 1);
11 } else { ret ack(m - 1, ack(m, n - 1)); }
d6b7c96 @graydon Populate tree.
graydon authored
12 }
13 }
14
15 fn main() {
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
16 assert (ack(0, 0) == 1);
17 assert (ack(3, 2) == 29);
18 assert (ack(3, 4) == 125);
19 // This takes a while; but a comparison may amuse: on win32 at least, the
20 // posted C version of the 'benchmark' running ack(4,1) overruns its stack
21 // segment and crashes. We just grow our stack (to 4mb) as we go.
d6b7c96 @graydon Populate tree.
graydon authored
22
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
23 // assert (ack(4,1) == 65533);
d6b7c96 @graydon Populate tree.
graydon authored
24
25 }
Something went wrong with that request. Please try again.