1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| module Main where
import Data.List
data NumberType = Deficient | Perfect | Abundant
deriving (Eq, Show)
numberRange = [1..20161]
main = do
print . sum $ numberRange \\ (pairSums abundantNumbers)
sigma n = sum $ factorsOf n
where factorsOf x = 1 : divisors x
abundantNumbers = filter_nType Abundant numberRange
where filter_nType nT = filter $ (== nT) . nType
pairSums xs = [ x+y | (x, y) <- pairs xs ]
where pairs xs = concat $ zipWith (map . (,)) xs (tails xs)
nType x
| s < x = Deficient
| s == x = Perfect
| otherwise = Abundant
where s = sigma x |