#!/bin/env ruby
require 'benchmark'
def phantom_five
numPrimes = 0;
currentTest = 2;
isPrime = 1;
while numPrimes<10000
for test in 2...(currentTest-1)
if (currentTest%test) == 0
isPrime = 0;
break;
end
end
if isPrime == 1
numPrimes = numPrimes + 1;
# puts "PF: found prime " + numPrimes.to_s + ": " + currentTest.to_s;
end
isPrime = 1;
currentTest = currentTest + 1;
end
puts "%d primes found" % [numPrimes]
end
def check_prime n
i = 2
while i < (n -1)
if n % i == 0
return false
end
i += 1
end
true
end
def aighy
number_of_primes = 0
n = 2
while number_of_primes < 10000
number_of_primes += 1 if check_prime(n)
n += 1
end
puts "%d primes found" % [ number_of_primes ]
end
Benchmark::bm(1) do |test|
# test.report("phantom_five") do
# phantom_five
# end
test.report("aighy") do
aighy
end
end