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⑈
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to