Primes by Trial Division - ruby

9 September 2016

module Benchmark

  def self.primes(n)
    primes = [2]
    count = 3
    begin
      primes.push(count) if primes.each do |prime|
        break if count%prime == 0
        prime
      end
      count += 1
    end until primes.length == n
    primes
  end

end

puts Benchmark.primes(ARGV[0].to_i)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026

Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Primes Benchmark Source

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

Primes Benchmark Results

Other Implementations

BCPL

perl

REXX

ruby

Tcl