Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created February 16, 2023 18:21
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 thinkphp/cc1ddd7570b0e98d192978c0bb161be0 to your computer and use it in GitHub Desktop.
Save thinkphp/cc1ddd7570b0e98d192978c0bb161be0 to your computer and use it in GitHub Desktop.
#
# 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