2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / tests / ackermann.cs
blob607f91aae253b03ada0bf6ff38b6c1d308219a13
1 // $Id$
2 // http://www.bagley.org/~doug/shootout/
4 public class ackermann {
6 public static int Main(string[] args) {
7 int NUM = 8;
8 if (args.Length > 0)
9 NUM = System.Int32.Parse (args [0]);
10 //return Ack(3, NUM) != 2045? 1: 0;
11 System.Console.WriteLine("Ack(3," + NUM + "): " + Ack(3, NUM));
12 return 0;
15 public static int Ack(int M, int N) {
16 if (M == 0) return( N + 1 );
17 if (N == 0) return( Ack(M - 1, 1) );
18 return( Ack(M - 1, Ack(M, (N - 1))) );