Skip to content
Newer
Older
100644 27 lines (18 sloc) 658 Bytes
2ec7abb Refactored libraries, added #10
Eric Wilson authored Jan 11, 2011
1 import EulerMath.Divisors
2 import EulerMath.Primes
16219ac First flailings toward 12.
Eric Wilson authored Jan 5, 2011
3
29a929a refactored 12 for speed.
Eric Wilson authored Jan 11, 2011
4 tri :: Int -> Int
16219ac First flailings toward 12.
Eric Wilson authored Jan 5, 2011
5 tri n = n * (n+1) `quot` 2
6
29a929a refactored 12 for speed.
Eric Wilson authored Jan 11, 2011
7 triDivs :: Int -> Int
064e4e7 Problem twelve, and a utility module
Eric Wilson authored Jan 5, 2011
8 triDivs n = if (even n)
29a929a refactored 12 for speed.
Eric Wilson authored Jan 11, 2011
9 then numDivs (quot n 2) * numDivs (n+1)
10 else numDivs n * numDivs (quot (n+1) 2)
16219ac First flailings toward 12.
Eric Wilson authored Jan 5, 2011
11
08b6f9a refactored 3 and 12 for speed and readability
Eric Wilson authored Jan 12, 2011
12 numDivs :: Int -> Int
13 numDivs n = product $ map (+1) $ primeFactorMultiplicity n
14
15 primeFactorMultiplicity :: Int -> [Int]
16 primeFactorMultiplicity = map snd . primeFactorizationFS primes1000
17 where primes1000 = primesUpTo 1000
18
19 euler12 :: Int -> Int
20 euler12 n = (\ (_, t, _) -> t) . head $ filter (tripleAbove n) $ map triDivTriple [1..]
2ec7abb Refactored libraries, added #10
Eric Wilson authored Jan 11, 2011
21 where
22 triDivTriple m = (m, tri m, triDivs m)
23 tripleAbove n (_, _, m) = (m > n)
24
29a929a refactored 12 for speed.
Eric Wilson authored Jan 11, 2011
25
08b6f9a refactored 3 and 12 for speed and readability
Eric Wilson authored Jan 12, 2011
26
Something went wrong with that request. Please try again.