/* The Great Win32 Language Shootout http://dada.perl.it/shootout/ contributed by Isaac Gouy (Nice novice) Transliterated from the Java implementation To compile: nicec --sourcepath=.. -d=. -a matrix.jar matrix To run: java -jar matrix.jar 300 */ // NOTE: the type of a variable declared with let // or var will be inferred by the compiler import ackermann; // reuse toSingleInt void main(String[] args){ var n = toSingleInt(args); let int SIZE = 30; let m1 = mkmatrix(SIZE, SIZE); let m2 = mkmatrix(SIZE, SIZE); let mm = new int[SIZE][SIZE]; while (n-- > 0) mmult(m1, m2, mm); print(mm[0][0]); print(" "); print(mm[2][3]); print(" "); print(mm[3][2]); print(" "); println(mm[4][4]); } int[][] mkmatrix(int nRows, int nCols) { int count = 1; let m = new int[nRows][nCols]; for (var i = 0; i < nRows; i++) for (var j = 0; j < nCols; j++) m[i][j] = count++; return m; } void mmult(int[][] m1, int[][] m2, int[][] m) { let nRows = m1.length; let nCols = nRows; // Assume a square matrix for (var i=0; i < nRows; i++) for (var j = 0; j < nCols; j++) { int val = 0; for (var k = 0; k < nCols; k++) val += m1[i][k] * m2[k][j]; m[i][j] = val; } }