diff options
author | rubidium <rubidium@openttd.org> | 2009-02-25 01:21:50 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-02-25 01:21:50 +0000 |
commit | 1ad50ce4e6ed74c8eeb89a1f2780e6ed58a72b2b (patch) | |
tree | 0955433146cc59335ddaac1d6e08eb177a9ead61 /src/3rdparty/squirrel/samples/ackermann.nut | |
parent | 66a8c0a1325e1f8717150dc6bbe1bcb4fb458bef (diff) | |
download | openttd-1ad50ce4e6ed74c8eeb89a1f2780e6ed58a72b2b.tar.xz |
(svn r15578) -Change: unexternalise squirrel.
Diffstat (limited to 'src/3rdparty/squirrel/samples/ackermann.nut')
-rw-r--r-- | src/3rdparty/squirrel/samples/ackermann.nut | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/3rdparty/squirrel/samples/ackermann.nut b/src/3rdparty/squirrel/samples/ackermann.nut new file mode 100644 index 000000000..c8d056082 --- /dev/null +++ b/src/3rdparty/squirrel/samples/ackermann.nut @@ -0,0 +1,22 @@ +/* +* +* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/) +* +*/ + +function Ack(M, N) { + if (M == 0) return( N + 1 ); + if (N == 0) return( Ack(M - 1, 1) ); + return( Ack(M - 1, Ack(M, (N - 1))) ); +} + +local n; + +if(ARGS.len()!=0) { + n = ARGS[0].tointeger(); + if(n < 1) n = 1; +} else { + n = 1; +} +print("n="+n+"\n"); +print("Ack(3,"+ n+ "):"+ Ack(3, n)); |