type PosInt = Int -- lightweight type synonym for integers > 0 divides :: PosInt -> PosInt -> Bool x `divides` y = (y `mod` x == 0) divisors :: PosInt -> [PosInt] divisors n = filter (`divides` n) [1 .. n `div` 2] combinations :: [a] -> [[a]] combinations [] = [[]] combinations (x:xs) = concatMap (\c -> [c, x:c]) (combinations xs) isPractical :: Int -> Bool isPractical n | n < 1 = error "isPractical: n must be positive" isPractical n = let sums = map sum . combinations . divisors $ n in all (`elem` sums) [2 .. n-1] main :: IO () main = putStrLn . show . sum . take 100 . filter isPractical $ [1..]