Last active
November 29, 2019 01:41
-
-
Save kaityo256/89526121b75ed2afabc0eee122180940 to your computer and use it in GitHub Desktop.
The Square root of 2
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 finda(r,s) | |
a = 1 | |
a = a + 1 while a**2 + 2*s*a < r | |
a - 1 | |
end | |
r = 2 | |
a = Math.sqrt(r).to_i | |
r = r - a**2 | |
s = a | |
50.times do | |
s = s * 10 | |
r = r * 100 | |
a = finda(r,s) | |
r = r - 2*s*a - a**2 | |
s = s + a | |
v = s.to_s | |
puts v[0] + "." + v[1,v.size] | |
end |
Author
kaityo256
commented
Oct 18, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment