aboutsummaryrefslogtreecommitdiff
path: root/0012/main.hs
blob: d40b1a5d78dda59488c723fb8f07d7f0cb1cf970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
divisors num = length $ filter divisable [1..num]
    where divisable x = num `mod` x == 0

pairDivisors (x,y) = (divisors x) * (divisors y)

triangleNums :: [(Integer,Integer)]
triangleNums = map toPair [1..]
    where
        toPair n = if n `mod` 2 == 0 then
                      (n `div` 2,n+1)
                   else
                      ((n+1) `div` 2, n)

firstWithDivisorNum n = impl triangleNums
    where impl ((a,b):xs) = if pairDivisors (a,b) >= n then (a * b) else impl xs

main = do
    putStrLn $ show $ firstWithDivisorNum 500