Created
February 16, 2023 18:21
-
-
Save thinkphp/cc1ddd7570b0e98d192978c0bb161be0 to your computer and use it in GitHub Desktop.
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
# | |
# Square Root Babylonian Method | |
# @Adrian Statescu | |
# | |
def sqrt_babylonian(n) | |
x = n | |
y = 1.0 | |
e = 0.000001 | |
while x - y > e | |
x = (x + y) / 2 | |
y = n / x | |
end | |
x | |
end | |
def func | |
n = gets.chomp.to_i | |
print sqrt_babylonian(n) | |
end | |
func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment