lib/primetable.rb
# Calculates the primes using basic math. This can be slow for higher primes or higher counts.
# TODO: Include note on computational complexity here: O(n*sqrt(n)), I think
# TODO: Include note on average run time using this method.
Calculates the primes using basic math. This can be slow for higher primes or higher counts.
TODO: Include note on computational complexity here: O(n*sqrt(n)), I think
TODO: Include note on average run time using this method.
Calculates the primes using basic math . This can be slow for higher primes or higher counts . TODO : Include note on computational complexity here : O ( n * sqrt ( n )) I think TODO : Include note on average run time using this method .
def calc_primes(first, count)
    calc_primes_js = V8::Context.new timeout: 7000
    File.open("#{ROOT_DIR}/js/prime.js") do |file|
      calc_primes_js.eval(file)
    end
    primes_js = calc_primes_js.eval("generatePrimes(#{first},#{count})")
    YAML::load("[#{primes_js}]")
  end
def calc_primes ( first , count ) calc_primes_js = V8 :: Context . new timeout : 7000 File . open ( "#{ROOT_DIR}/js/prime.js" ) do | file | calc_primes_js . eval ( file ) end primes_js = calc_primes_js . eval ( "generatePrimes(#{first},#{count})" ) YAML :: load ( "[#{primes_js}]" ) end
Calculates the primes using basic math.
Calculates the primes using basic math .
# One nice thing about this is that I can easily set a timeout, so if someone asks us to run # some astronomical prime, we won't seize up the CPU forever. 7000ms is arbitrary.
first
<not_specific>
count
<not_specific>