The Squirrel interpreter. See http://www.squirrel-lang.org/
samples/array.nut@0:97a4f8cc534c, 2014-12-16 (annotated)
- Committer:
- jhnwkmn
- Date:
- Tue Dec 16 10:20:34 2014 +0000
- Revision:
- 0:97a4f8cc534c
Initial import of Squirrel.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhnwkmn | 0:97a4f8cc534c | 1 | /* |
jhnwkmn | 0:97a4f8cc534c | 2 | * |
jhnwkmn | 0:97a4f8cc534c | 3 | * Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/) |
jhnwkmn | 0:97a4f8cc534c | 4 | * |
jhnwkmn | 0:97a4f8cc534c | 5 | */ |
jhnwkmn | 0:97a4f8cc534c | 6 | local n, i, k; |
jhnwkmn | 0:97a4f8cc534c | 7 | |
jhnwkmn | 0:97a4f8cc534c | 8 | if(vargv.len()!=0) { |
jhnwkmn | 0:97a4f8cc534c | 9 | n = vargv[0].tointeger(); |
jhnwkmn | 0:97a4f8cc534c | 10 | if(n < 1) n = 1; |
jhnwkmn | 0:97a4f8cc534c | 11 | } else { |
jhnwkmn | 0:97a4f8cc534c | 12 | n = 1; |
jhnwkmn | 0:97a4f8cc534c | 13 | } |
jhnwkmn | 0:97a4f8cc534c | 14 | |
jhnwkmn | 0:97a4f8cc534c | 15 | local x = []; x.resize(n); |
jhnwkmn | 0:97a4f8cc534c | 16 | local y = []; y.resize(n); |
jhnwkmn | 0:97a4f8cc534c | 17 | |
jhnwkmn | 0:97a4f8cc534c | 18 | for (i = 0; i < n; i+=1) { |
jhnwkmn | 0:97a4f8cc534c | 19 | x[i] = i + 1; |
jhnwkmn | 0:97a4f8cc534c | 20 | y[i] = 0; |
jhnwkmn | 0:97a4f8cc534c | 21 | } |
jhnwkmn | 0:97a4f8cc534c | 22 | |
jhnwkmn | 0:97a4f8cc534c | 23 | for (k = 0 ; k < n; k+=1) { |
jhnwkmn | 0:97a4f8cc534c | 24 | for (i = n-1; i >= 0; i-=1) { |
jhnwkmn | 0:97a4f8cc534c | 25 | y[i] = y[i]+ x[i]; |
jhnwkmn | 0:97a4f8cc534c | 26 | } |
jhnwkmn | 0:97a4f8cc534c | 27 | } |
jhnwkmn | 0:97a4f8cc534c | 28 | print(y[0].tostring()+" "+y[n-1]); |
jhnwkmn | 0:97a4f8cc534c | 29 |