3 # The Great Computer Language Shootout
4 # http://shootout.alioth.debian.org/
7 # Contributed by Glenn Parker, March 2005
10 BitsPerChar = 1 << CharExponent
11 LowMask = BitsPerChar - 1
14 items = "\xFF" * ((m / BitsPerChar) + 1)
16 BitsPerChar.times do |b|
22 2.step(pmax, 1) do |p|
23 if items[p >> CharExponent][p & LowMask] == 1
25 p.step(pmax, p) do |mult|
26 a = mult >> CharExponent
28 items[a] -= masks[b] if items[a][b] != 0
35 n = 9 # (ARGV[0] || 2).to_i
36 n.step(n - 2, -1) do |exponent|
38 m = 2 ** exponent * 10_000
40 printf "Primes up to %8d %8d\n", m, count