Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // The Great Computer Language Shootout |
michael@0 | 2 | // http://shootout.alioth.debian.org/ |
michael@0 | 3 | // |
michael@0 | 4 | // modified by Isaac Gouy |
michael@0 | 5 | |
michael@0 | 6 | function pad(number,width){ |
michael@0 | 7 | var s = number.toString(); |
michael@0 | 8 | var prefixWidth = width - s.length; |
michael@0 | 9 | if (prefixWidth>0){ |
michael@0 | 10 | for (var i=1; i<=prefixWidth; i++) s = " " + s; |
michael@0 | 11 | } |
michael@0 | 12 | return s; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function nsieve(m, isPrime){ |
michael@0 | 16 | var i, k, count; |
michael@0 | 17 | |
michael@0 | 18 | for (i=2; i<=m; i++) { isPrime[i] = true; } |
michael@0 | 19 | count = 0; |
michael@0 | 20 | |
michael@0 | 21 | for (i=2; i<=m; i++){ |
michael@0 | 22 | if (isPrime[i]) { |
michael@0 | 23 | for (k=i+i; k<=m; k+=i) isPrime[k] = false; |
michael@0 | 24 | count++; |
michael@0 | 25 | } |
michael@0 | 26 | } |
michael@0 | 27 | return count; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | var ret = 0; |
michael@0 | 31 | function sieve() { |
michael@0 | 32 | for (var i = 1; i <= 3; i++ ) { |
michael@0 | 33 | var m = (1<<i)*10000; |
michael@0 | 34 | var flags = Array(m+1); |
michael@0 | 35 | ret += nsieve(m, flags); |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | sieve(); |
michael@0 | 40 | assertEq(ret, 14302) |