Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
202 lines (195 sloc) 18.5 KB
- Solution to Project Euler problem 42
- Copyright (c) Project Nayuki. All rights reserved.
import Data.Char (ord)
import qualified EulerLib
main = putStrLn (show ans)
ans = EulerLib.count isTriangular (map wordValue englishWords)
isTriangular n = (last (takeWhile (<= n) triangleNumbers)) == n
triangleNumbers = [div (n * (n + 1)) 2 | n <- [1..]] -- [1, 3, 6, 10, 15, 21, 28, ...]
wordValue :: String -> Int
wordValue = sum . (map (\c -> (ord c) - (ord 'A') + 1))
englishWords = [ -- 10 strings per line, except final line