Day 5: Doesn’t He Have Intern-Elves For This?
Section
defmodule P1 do
def three_vowels?(s) do
Regex.scan(~r/[aeiouAEIOU]/, s)
|> Enum.count() >= 3
end
def repeated_letter?(s) do
Regex.match?(~r/(.)\1/, s)
end
def contain_strings?(s) do
not Regex.match?(~r/ab|cd|pq|xy/, s)
end
def nice?(s) do
three_vowels?(s) and repeated_letter?(s) and contain_strings?(s)
end
end
{:ok, data} = File.read("/Users/eli/Desktop/input.txt")
data
|> String.split()
|> Enum.count(&P1.nice?/1)
238
defmodule P2 do
def pair_letters?(s) do
Regex.match?(~r/(..).*\1/, s)
end
def xyx?(s) do
Regex.match?(~r/(.).\1/, s)
end
def nice?(s) do
pair_letters?(s) and xyx?(s)
end
end
{:ok, data} = File.read("/Users/eli/Desktop/input.txt")
data
|> String.split()
|> Enum.count(&P2.nice?/1)
69