Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
奥村晴彦他『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