Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Created March 10, 2017 14:08
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 hyuki0000/c756685730d082d0358a38b1ed6ed483 to your computer and use it in GitHub Desktop.
Save hyuki0000/c756685730d082d0358a38b1ed6ed483 to your computer and use it in GitHub Desktop.
奥村晴彦他『Javaによるアルゴリズム事典』p.290をRubyで
# 奥村晴彦他『Javaによるアルゴリズム事典』p.290をRubyで
def sqrt(n)
r = n
t = 0
while t != r do
t = r
r = (n / r + r) / 2
end
r
end
puts sqrt(55225) # => 235
puts sqrt(3972150625) # => 63025
puts sqrt(20000000000000000) # => 141421356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment