Skip to content

Instantly share code, notes, and snippets.

@mikamix
Last active January 2, 2016 01:59
Show Gist options
  • Select an option

  • Save mikamix/8234305 to your computer and use it in GitHub Desktop.

Select an option

Save mikamix/8234305 to your computer and use it in GitHub Desktop.
import Data.List
main = print $ head $ filter ((> 500) . countDivisors) triangleNumbers
triangleNumbers = scanl1 (+) [1..]
countDivisors n = product $ map ((+1) . length) (group (primeFactors n))
primeFactors n = primeFactors' n 2
where
primeFactors' n f
| f ^ 2 > n = [n]
| n `mod` f == 0 = f : primeFactors' (n `div` f) f
| otherwise = primeFactors' n (f + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment