2015 Day 05 in Haskell
This commit is contained in:
parent
bc148ac3b7
commit
a8ae522c3a
18
2015/day05/day05.hs
Normal file
18
2015/day05/day05.hs
Normal 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
|
Loading…
Reference in New Issue
Block a user