Life Goes On

まあまあだけど楽しんでる方です

12問目

http://projecteuler.net/index.php?section=problems&id=12
501個以上の約数をもつ最初の三角数を求める。
nの約数の個数は√n以下の約数の個数を2倍しています。
厳密には、nが平方数のときは1少ない数になりますが、大勢に影響ないので無視しています。

main = print $ euler012 500

euler012 :: Int -> Int
euler012 limit = head $ dropWhile ((<= limit) . divisors) triangles

triangles :: [Int]
triangles = scanl1 (+) [1..]

divisors :: Int -> Int
divisors n = (* 2) $ length $
  filter ((== 0) . (mod n)) [1..root]
    where root = floor $ sqrt $ fromIntegral n