Skip to content

Instantly share code, notes, and snippets.

@mstahl
Created December 10, 2008 17:39
Show Gist options
  • Save mstahl/34417 to your computer and use it in GitHub Desktop.
Save mstahl/34417 to your computer and use it in GitHub Desktop.
module Main where
import Control.Parallel
import Control.Parallel.Strategies
import Data.List
import qualified Data.IntSet as Set
divisors :: (Integral t) => t -> [t]
divisors n = nub $ divs ++ inv_divs
where divs = [d | d <- [1..((floor . sqrt . fromIntegral) n)], n `mod` d == 0]
inv_divs = [n `div` d | d <- divs]
is_abundant :: (Integral t) => t -> Bool
is_abundant n = sum (divisors n) > 2 * n
abundants :: [Int]
abundants = [a | a <- [1..20161], is_abundant a]
bigZip :: (a -> b -> c) -> [a] -> [b] -> [c]
bigZip fn (x:xs) lstb = (next `par` ((map (fn x) lstb))) ++ next
where next = bigZip fn xs lstb
bigZip fn [] _ = []
abundantables = Set.fromList $ filter (<=20161) $ bigZip (+) abundants abundants
main :: IO ()
main = do print $ (sum [1..20161]) - (Set.fold (+) 0 abundantables)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment