Created
March 10, 2017 14:08
-
-
Save hyuki0000/c756685730d082d0358a38b1ed6ed483 to your computer and use it in GitHub Desktop.
奥村晴彦他『Javaによるアルゴリズム事典』p.290をRubyで
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
# 奥村晴彦他『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