array.nut 469 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. *
  3. * Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
  4. *
  5. */
  6. local n, i, k;
  7. if(vargv.len()!=0) {
  8. n = vargv[0].tointeger();
  9. if(n < 1) n = 1;
  10. } else {
  11. n = 1;
  12. }
  13. local x = []; x.resize(n);
  14. local y = []; y.resize(n);
  15. for (i = 0; i < n; i+=1) {
  16. x[i] = i + 1;
  17. y[i] = 0;
  18. }
  19. for (k = 0 ; k < n; k+=1) {
  20. for (i = n-1; i >= 0; i-=1) {
  21. y[i] = y[i]+ x[i];
  22. }
  23. }
  24. print(y[0].tostring()+" "+y[n-1]);