// -*- mode: java -*-
// $Id: ary3.njs,v 1.1 2001/07/08 20:20:06 doug Exp $
// http://www.bagley.org/~doug/shootout/
// By David Hedbor
// modified by Aldo Calpini <dada@perl.it> for Win32

var n, i, k;

ARGS = WScript.Arguments

if(ARGS.length > 0) {
  n = parseInt(ARGS.Item(0), "10");
  if(n < 1) n = 1;
} else {   
  n = 1000;
}
var x = Array(n);
var y = Array(n);

for (i = 0; i < n; i++) {
  x[i] = i + 1;
  y[i] = 0; // Need to set all entries in i to zero or the result will be NaN 
}
for (k = 0 ; k < 1000; k++) {
  for (i = n-1; i >= 0; i--) {
    y[i] += x[i];
  }
}
WScript.Echo(y[0], y[n-1]);