Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: computing square root by hand -- no sqrt (golf, beginner)

by jynx (Priest)
on May 09, 2002 at 21:01 UTC ( #165510=note: print w/ replies, xml ) Need Help??


in reply to computing square root by hand -- no sqrt (golf, beginner)


While playing around, i thought i would (jokingly) try to golf Matt's solution and found something interesting. Using subtraction instead of bit-xor is more accurate. So, cleaning up my current mess of solutions and using subtraction for accuracy, it's now 49 chars (52 to print a carriage return):

#23456789_123456789_123456789_123456789_123456789_123456789_ $_=pop;$l=$_,($_+=$ARGV[0]/$_)/=2while$l-$_;print
jynx

update:an approximation method:

# 44 #23456789_123456789_123456789_123456789_123456789_ $a=pop;($a+=$ARGV[0]/$a)/=2for-9..99;print$a


Comment on Re: computing square root by hand -- no sqrt (golf, beginner)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://165510]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-07-31 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (282 votes), past polls