{-# LANGUAGE OverloadedStrings #-}
module Euler.Problems.Problem42
( answer
, parseWords
, isTriangleWord
) where
import Euler.Prelude
import Euler.Util.FigurateNumbers (isTriangle)
import Euler.Util.WordScore (wordScoreText)
import qualified Data.List as List
import qualified Data.Text as Text
type InputText = Text
answer :: InputText -> Integer
answer =
parseWords >>>
List.filter isTriangleWord >>>
List.length >>>
fromIntegral
parseWords :: InputText -> [Text]
parseWords =
Text.filter (/= '"') >>>
Text.splitOn ","
isTriangleWord :: Text -> Bool
isTriangleWord =
wordScoreText >>>
isTriangle