Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by japhy (Canon)
on May 09, 2002 at 18:17 UTC ( [id://165454]=note: print w/replies, xml ) Need Help??


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

Golfing to 59:
($n,$_)=@ARGV;{$l^($_=($_+$n/$_)/2)||exit print;$l=$_;redo}

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: computing square root by hand -- no sqrt (golf, beginner)
by jynx (Priest) on May 09, 2002 at 20:03 UTC

    a reinterpretation of japhy's solution gives 54:
    $_=pop;$l^$_?$l=$_:die"$_\n"while$_=($_+$ARGV[0]/$_)/2
    jynx

    update: this works at 53:

    $_=pop;$l^$_?$l=$_:die"$_\n"while($_+=$ARGV[0]/$_)/=2
    update2: using the comma instead of quotes for die it's 52:
    $_=pop;$l^$_?$l=$_:die$_,$/while($_+=$ARGV[0]/$_)/=2

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found