santasList = File.stream!("inputs/day5.txt") niceVowelRegex = ~r/[aeiou].*[aeiou].*[aeiou]/ niceDuplicateRegex = ~r/(.)\1/ naughtySubstrRegex = ~r/(ab)|(cd)|(pq)|(xy)/ isNice1 = fn name -> niceVowels? = Regex.match?(niceVowelRegex, name) niceDuplicate? = Regex.match?(niceDuplicateRegex, name) naughtySustr? = Regex.match?(naughtySubstrRegex, name) niceVowels? && niceDuplicate? && !naughtySustr? end niceCount1 = Enum.filter(santasList, isNice1) |> Enum.count() IO.puts("Nice count 1: #{niceCount1}") niceDuplicatePairRegex = ~r/(..).*\1/ niceLetterRepeatRegex = ~r/(.).\1/ isNice2 = fn name -> niceDuplicatePair? = Regex.match?(niceDuplicatePairRegex, name) niceLetterRepeat? = Regex.match?(niceLetterRepeatRegex, name) niceDuplicatePair? && niceLetterRepeat? end niceCount2 = Enum.filter(santasList, isNice2) |> Enum.count() IO.puts("Nice count 2: #{niceCount2}")