Monday, March 28, 2016

today in oblique approaches

If your standard library offers complex numbers and you're not in any hurry, you can't ask for much simpler (or more obscure) ways to compute pi than this.
import Data.Complex (magnitude, Complex((:+)))
 
pi = length $ takeWhile (< 2) $ map magnitude zs
 where
  zs = iterate (\z -> z^2 + ((-0.75) :+ 0.0000001)) 0

No comments:

Post a Comment