
12 Jan
2008
12 Jan
'08
5:28 p.m.
On Jan 12, 2008 7:12 PM, Achim Schneider
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.
I did something similar:
isSquare :: Integer -> Bool
isSquare x = x == (sqx * sqx)
where sqx = round $ sqrt $ fromInteger x
perfectSquares :: [Integer]
perfectSquares = zipWith (*) [1..] [1..]
findSorted :: [Integer] -> Integer -> Bool
findSorted xs x = h == x
where h : _ = dropWhile (