prime

Ruby program. A program that will determine the primality of any number that Ruby can handle on your system. I've since been trying to make it faster.

def prime(a)
if(a==2)
return true
end

if(a<=1 || a%2==0)
return false
end

d=3

while d<=Math.sqrt(a)
if(a%d==0)
return false
end
d+=2
end

return true
end

#main method
if __FILE__ == $0
print "primality of...? "
a=gets.to_i
puts prime(a)
end

blog stats