I ran across this Dr. Math faq and thought it would make a nifty intro to perl golf( in that the algorithm is pretty simple).

your script should take 2 inputs on the command line, the first being the number we're looking for the root of, and a first 'best guess' Again, don't use sqrt in your code. Stop guessing when you have a reasonable idea of what the answer is, and print it out.

Your code isn't responsible for error checking or verifying that the output's correct (verify it with a calculator if you like).
here's an outline of the algorithm described in the first section of the above url:

First, start by guessing a square root value. It helps if
your guess is a good one but it will work even if it is a
terrible guess. We will guess that 2 is the square root of 12.
In step two, we divide 12 by our guess of 2 and we get 6.
In step three, we average 6 and 2: (6+2)/2 = 4
Now we repeat step two with the new guess of 4. So 12/4 = 3
Now average 4 and 3: (4+3)/2 = 3.5
Repeat step two: 12/3.5 = 3.43
Average: (3.5 + 3.43)/2 = 3.465

some sample input/output :
C:\>sqrt 701 25 26.4764404223228 C:\>sqrt 12 2 3.46428571428571 C:\>sqrt 120 10 10.9544511505092
All of these have have a precision of 3 digits.

my answer, at 66 characters, below :
($n,$_)=@ARGV;while(1){$_=($_+$n/$_)/2;($l^$_)||print&&exit;$l=$_}

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.