
12 Jan
2008
12 Jan
'08
5:15 p.m.
On Sat, 12 Jan 2008, Achim Schneider wrote:
"Rafael Almeida"
wrote: perfectSquares :: [Integer] perfectSquares = zipWith (*) [1..] [1..]
isPerfectSquare :: Integer -> Bool isPerfectSquare x = (head $ dropWhile (
what about
module Main where
isPerfectSquare :: Integer -> Bool isPerfectSquare n = sqrrt == fromIntegral (truncate sqrrt) where sqrrt = sqrt $ fromIntegral n
? It's a hell alot faster, but I have no idea if some numerical property of square roots could make it give different results than your version, in rare cases.
The rare cases occur for big numbers. http://www.haskell.org/haskellwiki/Generic_number_type#isSquare