You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
522 B

#!/usr/bin/env ruby
# Ruby version of a Prime Number Finder
# haplo@mindstab.net
include Math
class Primes
def findPrimes(cmax)
3.step(cmax,2) { |i|
max = sqrt(i)
isPrime = 1
3.step(max, 2) { |x|
isPrime = i % x
if isPrime == 0
break
end
}
if isPrime != 0
print i, "\n"
end
}
end
end
MAX = ARGV[0].to_i;
if ! MAX
print "primes.rb <MAX NUM>\n"
exit(1)
elsif MAX < 1
print "Invalid MAX Input\n"
exit(1)
end
prime = Primes.new();
prime.findPrimes(MAX);