summaryrefslogtreecommitdiff
path: root/src/3rdparty/squirrel/samples/ackermann.nut
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-25 01:21:50 +0000
committerrubidium <rubidium@openttd.org>2009-02-25 01:21:50 +0000
commit1ad50ce4e6ed74c8eeb89a1f2780e6ed58a72b2b (patch)
tree0955433146cc59335ddaac1d6e08eb177a9ead61 /src/3rdparty/squirrel/samples/ackermann.nut
parent66a8c0a1325e1f8717150dc6bbe1bcb4fb458bef (diff)
downloadopenttd-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.nut22
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));