head 1.2; access; symbols MOZILLA_JS_1_6_20070208:1.1.1.1 MOZILLA_JS_1_6_20070102:1.1.1.1 MOZILLA_JS_1_6_20060916:1.1.1.1 MOZILLA_JS_1_6_20060820:1.1.1.1 MOZILLA_JS_1_6_20060803:1.1.1.1 MOZILLA_JS_1_6_20060731:1.1.1.1 MOZILLA_JS_1_6_20060730:1.1.1.1 MOZILLA_JS_1_6_20060729:1.1.1.1 MOZILLA_JS_1_6_20060724:1.1.1.1 JS_1_6-1_5_0_5-20060722:1.1.1.1 MOZILLA:1.1.1; locks; strict; comment @# @; 1.2 date 2006.07.22.10.36.42; author rse; state dead; branches; next 1.1; commitid zYqZH6dTMkAdnQFr; 1.1 date 98.04.24.01.28.38; author rse; state Exp; branches 1.1.1.1; next ; commitid yL3y5cCdrhpJcQFr; 1.1.1.1 date 98.04.24.01.28.38; author rse; state Exp; branches; next ; commitid yL3y5cCdrhpJcQFr; desc @@ 1.2 log @remove files we do not use at all @ text @// Some simple testing of new, eval and some string stuff. // constructor -- expression array initialization function ExprArray(n,v) { // Initializes n values to v coerced to a string. for (var i = 0; i < n; i++) { this[i] = "" + v; } } // Print the perfect numbers up to n and the sum expression for n's divisors. function perfect(n) { print("The perfect numbers up to " + n + " are:"); // We build sumOfDivisors[i] to hold a string expression for // the sum of the divisors of i, excluding i itself. var sumOfDivisors = new ExprArray(n+1,1); for (var divisor = 2; divisor <= n; divisor++) { for (var j = divisor + divisor; j <= n; j += divisor) { sumOfDivisors[j] += " + " + divisor; } // At this point everything up to 'divisor' has its sumOfDivisors // expression calculated, so we can determine whether it's perfect // already by evaluating. if (eval(sumOfDivisors[divisor]) == divisor) { print("" + divisor + " = " + sumOfDivisors[divisor]); } } print("That's all."); } print("\nA number is 'perfect' if it is equal to the sum of its") print("divisors (excluding itself).\n"); perfect(500); @ 1.1 log @Initial revision @ text @@ 1.1.1.1 log @Import new upstream version: Mozilla JavaScript 1.6-1.5.0.5-20060722 @ text @@