From f7a424a3c93784b56fead7644a59e91eaad149b1 Mon Sep 17 00:00:00 2001 From: dclavijo Date: Tue, 5 Sep 2023 14:26:44 -0300 Subject: [PATCH] add another algorithm --- sqrttest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sqrttest.py b/sqrttest.py index 60e82a2..fed36e7 100644 --- a/sqrttest.py +++ b/sqrttest.py @@ -15,6 +15,15 @@ def sqrt(x): return r +def sqrt(n): + x = n + y = 1 + e = 0.00000001 + while (x - y) > e: + x = (x + y) / 2 + y = n / x + return x + # given the x**2-2=0 condition we bruteforce an aproximation to sqrt(2)