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