~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/3rdparty/squirrel/samples/matrix.nut

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*
 
3
* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
 
4
*
 
5
*/
 
6
local SIZE=30;
 
7
 
 
8
function mkmatrix(rows, cols) {
 
9
  local i, j, count = 1;
 
10
  local m = []; m.resize(rows);
 
11
  for (i = 0; i < rows; i+=1) {
 
12
    m[i] = [];m[i].resize(cols)
 
13
    for (j = 0; j < cols; j+=1) {
 
14
      m[i][j] = count+=1;
 
15
    }
 
16
  }
 
17
  return m;
 
18
}
 
19
 
 
20
function mmult(rows, cols,  m1, m2, m3) {
 
21
  local i, j, k, val;
 
22
  for (i = 0; i < rows; i+=1) {
 
23
    for (j = 0; j < cols; j+=1) {
 
24
      val = 0;
 
25
      for (k = 0; k < cols; k+=1) {
 
26
        val += m1[i][k] * m2[k][j];
 
27
      }
 
28
      m3[i][j] = val;
 
29
    }
 
30
  }
 
31
  return m3;
 
32
}
 
33
 
 
34
local n = ARGS.len()!=0?ARGS[0].tointeger():1
 
35
 
 
36
local m1 = mkmatrix(SIZE, SIZE);
 
37
local m2 = mkmatrix(SIZE, SIZE);
 
38
local mm = mkmatrix(SIZE, SIZE);
 
39
 
 
40
for (local i = 0; i < n; i+=1) {
 
41
  mmult(SIZE, SIZE, m1, m2, mm);
 
42
}
 
43
 
 
44
print(mm[0][0]+" "+mm[2][3]+" "+mm[3][2]+" "+mm[4][4]);