Perfect numbers: Difference between revisions

m
→‎{{header|Haskell}}: Moved a bracket, edited a comment.
(→‎{{header|Haskell}}: use list comprehension)
m (→‎{{header|Haskell}}: Moved a bracket, edited a comment.)
Line 1,159:
 
 
or, restricting the search space to improve performance:
or, using a simple restriction of the search space:
<lang haskell>isPerfect :: Int -> Bool
isPerfect n =
let lows = filter ((0 ==) . rem n) [1 .. floor (sqrt (fromIntegral n))]
in 1 < n &&
(sum $
(lows ++
[ y
[ y | x <- lows, let y = n `quot` x, x /= y ])
`quot` 2| x <- lows ==
[ y | x <- lows, let y = n `quot` x, x /= y ])
, x /= y ]) `quot`
2 ==
n
 
9,659

edits