Skip to content

Instantly share code, notes, and snippets.

@ghulette
Created February 7, 2011 18:52
Show Gist options
  • Save ghulette/814943 to your computer and use it in GitHub Desktop.
Save ghulette/814943 to your computer and use it in GitHub Desktop.
escapes1 :: RealFloat a => Int -> Complex a -> Bool
escapes1 i c = any ((>) 2 . magnitude) (take i ps)
where ps = iterate p (0 :+ 0)
p = \z -> c + z^(2 :: Int)
escapes2 :: RealFloat a => Int -> Complex a -> Bool
escapes2 i c = escapes2' i c (0 :+ 0)
escapes2' :: RealFloat a => Int -> Complex a -> Complex a -> Bool
escapes2' 0 _ _ = False
escapes2' !i !c !z =
if magnitude z' > 2 then True else escapes2' (pred i) c z'
where z' = c + z^(2 :: Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment