+ 3
This is my take on the cube root challenge - it's performing well, but the main flow is sort of ugly. Suggestions are welcome!
10 Respostas
+ 1
Look on this code :
def root3(n):
l=1
while l**3<n:
l*=10
l,k = l/10,l/100
while abs(n-l**3)>0.0001:
while l**3<n:
l+=k
l-=k
k/=10
return(round(l,4))
The first while loop corresponds to your ranger function. The second while loop corresponds to the calls of your subtractor function. The third while loop corresponds to your subtractor function.
Your ranger function can be optimized, since it search with single steps.
+ 2
It‘s not really similar to the newton method as far as I can tell. I wrote an example implementation for you: https://code.sololearn.com/cvsr1hdEoi11/?ref=app
+ 1
Try Newton’s method
+ 1
just do:
x**(1/3)
where x is the number you want the cube root of.
+ 1
Max - i thought my method was very similar to Newtons, no?
+ 1
Ulisses Cruz - thanks, but that's too boring :) 😂
+ 1
Max - thank you very much. Great code!
0
lemmi - thanks for the input! Great explanation
0
hi
0
nice day