Skip to content

Instantly share code, notes, and snippets.

@ednasawe
Created September 30, 2016 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ednasawe/8480490a514ae2f450d95cfdb46d9349 to your computer and use it in GitHub Desktop.
Save ednasawe/8480490a514ae2f450d95cfdb46d9349 to your computer and use it in GitHub Desktop.
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