ackermann.nut 420 B

123456789101112131415161718192021222324
  1. /*
  2. *
  3. * Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
  4. *
  5. */
  6. function Ack(M, N) {
  7. if (M == 0) return( N + 1 );
  8. if (N == 0) return( Ack(M - 1, 1) );
  9. return( Ack(M - 1, Ack(M, (N - 1))) );
  10. }
  11. local n;
  12. if(vargv.len()!=0) {
  13. n = vargv[0].tointeger();
  14. if(n < 1) n = 1;
  15. } else {
  16. n = 1;
  17. }
  18. print("n="+n+"\n");
  19. print("Ack(3,"+ n+ "):"+ Ack(3, n));