Created
September 30, 2016 19:23
-
-
Save ednasawe/8480490a514ae2f450d95cfdb46d9349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def squareroot(n, diff) | |
gues=refine(1,n) | |
while(((gues*gues)-n)>diff) | |
gues=refine(gues, n) | |
end | |
gues | |
end | |
def refine(gues, n) | |
gues=(gues+(n/gues))/2.0 | |
end | |
def is_primeno?(n) | |
s=squareroot(n, 0.00000001).to_i | |
rang=2..s | |
is_prime=true | |
rang.each do |c| | |
is_prime=false if (n%c == 0) | |
end | |
puts is_prime | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment