
23 Mar
2007
23 Mar
'07
5:26 p.m.
On Fri, Mar 23, 2007 at 01:04:47PM +0200, Logesh Pillay wrote:
my_sqrt t = last (take 20 (iterate (\n -> n/2 + t/(2 * n)) t))
It is a bit crude though. 20 iterations is a bit arbitrary. I don't suppose there is a easy way to iterate until the results stop changing.
perhaps
sqrt t = head [ n | (n,True) <- iterate (\n -> let n' = n/2 + t/(2 * n) in (n',n' == n)) t ]
John -- John Meacham - ⑆repetae.net⑆john⑈