Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 27 lines (18 sloc) 0.658 kb
2ec7abb Refactored libraries, added #10
Eric Wilson authored
1 import EulerMath.Divisors
2 import EulerMath.Primes
16219ac First flailings toward 12.
Eric Wilson authored
3
29a929a refactored 12 for speed.
Eric Wilson authored
4 tri :: Int -> Int
16219ac First flailings toward 12.
Eric Wilson authored
5 tri n = n * (n+1) `quot` 2
6
29a929a refactored 12 for speed.
Eric Wilson authored
7 triDivs :: Int -> Int
064e4e7 Problem twelve, and a utility module
Eric Wilson authored
8 triDivs n = if (even n)
29a929a refactored 12 for speed.
Eric Wilson authored
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
11
08b6f9a refactored 3 and 12 for speed and readability
Eric Wilson authored
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
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
25
08b6f9a refactored 3 and 12 for speed and readability
Eric Wilson authored
26
Something went wrong with that request. Please try again.