function within(next_result_function, epsilon) prev_result = next_result_function() curr_result = next_result_function() while math.abs(prev_result - curr_result) > epsilon do prev_result = curr_result curr_result = next_result_function() end return curr_result end function newton_raphson_sqrt(radicand, epsilon, guess) square_root = guess function next() square_root = (square_root + radicand / square_root) / 2.0 return square_root end return within(next, epsilon) end print(newton_raphson_sqrt(9.0, 1e-2, 10.0)) print(newton_raphson_sqrt(9.0, 1e-9, 10.0))