summaryrefslogtreecommitdiff
path: root/src/3rdparty/squirrel/samples/matrix.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/matrix.nut
parent66a8c0a1325e1f8717150dc6bbe1bcb4fb458bef (diff)
downloadopenttd-1ad50ce4e6ed74c8eeb89a1f2780e6ed58a72b2b.tar.xz
(svn r15578) -Change: unexternalise squirrel.
Diffstat (limited to 'src/3rdparty/squirrel/samples/matrix.nut')
-rw-r--r--src/3rdparty/squirrel/samples/matrix.nut44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/3rdparty/squirrel/samples/matrix.nut b/src/3rdparty/squirrel/samples/matrix.nut
new file mode 100644
index 000000000..c8b16c65a
--- /dev/null
+++ b/src/3rdparty/squirrel/samples/matrix.nut
@@ -0,0 +1,44 @@
+/*
+*
+* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
+*
+*/
+local SIZE=30;
+
+function mkmatrix(rows, cols) {
+ local i, j, count = 1;
+ local m = []; m.resize(rows);
+ for (i = 0; i < rows; i+=1) {
+ m[i] = [];m[i].resize(cols)
+ for (j = 0; j < cols; j+=1) {
+ m[i][j] = count+=1;
+ }
+ }
+ return m;
+}
+
+function mmult(rows, cols, m1, m2, m3) {
+ local i, j, k, val;
+ for (i = 0; i < rows; i+=1) {
+ for (j = 0; j < cols; j+=1) {
+ val = 0;
+ for (k = 0; k < cols; k+=1) {
+ val += m1[i][k] * m2[k][j];
+ }
+ m3[i][j] = val;
+ }
+ }
+ return m3;
+}
+
+local n = ARGS.len()!=0?ARGS[0].tointeger():1
+
+local m1 = mkmatrix(SIZE, SIZE);
+local m2 = mkmatrix(SIZE, SIZE);
+local mm = mkmatrix(SIZE, SIZE);
+
+for (local i = 0; i < n; i+=1) {
+ mmult(SIZE, SIZE, m1, m2, mm);
+}
+
+print(mm[0][0]+" "+mm[2][3]+" "+mm[3][2]+" "+mm[4][4]);