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
27
28
29
| module Main where
import Euler
import Data.List
import Control.Parallel.Strategies
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
sum' = foldl' (+) 0 |