advent-of-code/2015/day05/day05.hs

18 lines
504 B
Haskell
Raw Normal View History

2024-12-03 01:51:43 +11:00
import Aoc
import Text.Regex.PCRE
part1 :: [String] -> Int
part1 = length . filter (\str -> hasVowels str && hasDouble str && not (hasForbidden str))
where
hasVowels = (=~ "([aeiou].*){3}")
hasDouble = (=~ "(\\w)\\1")
hasForbidden = (=~ "(ab|cd|pq|xy)")
part2 :: [String] -> Int
part2 = length . filter (\str -> hasPair str && hasBetween str)
where
hasPair = (=~ "(\\w\\w).*\\1")
hasBetween = (=~ "(\\w).\\1")
main :: IO ()
main = aocMain id part1 part2