ProjectEular

-- Problem 12

module Main (main) where

import qualified Common as C (divisors)

main :: IO ()
main = print $ problem12

problem12 :: (Integral a) => (a, a)
problem12 = calc_iter (1, (triangle 1)) 500

calc_iter :: (Integral a) => (a, a) -> Int -> (a, a)
calc_iter (nth,tri) max
    | count_divisors tri > max = (nth,tri)
    | otherwise                = calc_iter (nth+1, tri+(nth+1)) max

count_divisors :: (Integral a) => a -> Int
count_divisors num = length $ C.divisors num

triangle :: (Integral a) => a -> a
triangle num = sum [1..num]

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS