2015 Day 05 in Haskell

This commit is contained in:
germax26 2024-12-03 01:51:43 +11:00
parent bc148ac3b7
commit a8ae522c3a
Signed by: germax26
SSH Key Fingerprint: SHA256:N3w+8798IMWBt7SYH8G1C0iJlIa2HIIcRCXwILT5FvM

18
2015/day05/day05.hs Normal file
View File

@ -0,0 +1,18 @@
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