The Squirrel interpreter. See http://www.squirrel-lang.org/
samples/ackermann.nut@3:7268a3ceaffc, 2014-12-16 (annotated)
- Committer:
- jhnwkmn
- Date:
- Tue Dec 16 11:39:42 2014 +0000
- Revision:
- 3:7268a3ceaffc
- Parent:
- 0:97a4f8cc534c
Accepts \r as line terminator as well.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhnwkmn | 0:97a4f8cc534c | 1 | /* |
jhnwkmn | 0:97a4f8cc534c | 2 | * |
jhnwkmn | 0:97a4f8cc534c | 3 | * Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/) |
jhnwkmn | 0:97a4f8cc534c | 4 | * |
jhnwkmn | 0:97a4f8cc534c | 5 | */ |
jhnwkmn | 0:97a4f8cc534c | 6 | |
jhnwkmn | 0:97a4f8cc534c | 7 | function Ack(M, N) { |
jhnwkmn | 0:97a4f8cc534c | 8 | if (M == 0) return( N + 1 ); |
jhnwkmn | 0:97a4f8cc534c | 9 | if (N == 0) return( Ack(M - 1, 1) ); |
jhnwkmn | 0:97a4f8cc534c | 10 | return( Ack(M - 1, Ack(M, (N - 1))) ); |
jhnwkmn | 0:97a4f8cc534c | 11 | } |
jhnwkmn | 0:97a4f8cc534c | 12 | |
jhnwkmn | 0:97a4f8cc534c | 13 | local n; |
jhnwkmn | 0:97a4f8cc534c | 14 | |
jhnwkmn | 0:97a4f8cc534c | 15 | if(vargv.len()!=0) { |
jhnwkmn | 0:97a4f8cc534c | 16 | n = vargv[0].tointeger(); |
jhnwkmn | 0:97a4f8cc534c | 17 | if(n < 1) n = 1; |
jhnwkmn | 0:97a4f8cc534c | 18 | } else { |
jhnwkmn | 0:97a4f8cc534c | 19 | n = 1; |
jhnwkmn | 0:97a4f8cc534c | 20 | } |
jhnwkmn | 0:97a4f8cc534c | 21 | print("n="+n+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 22 | print("Ack(3,"+ n+ "):"+ Ack(3, n)); |
jhnwkmn | 0:97a4f8cc534c | 23 |