diff options
author | Justin Wernick <j.wernick@eyeo.com> | 2024-09-11 11:09:39 +0200 |
---|---|---|
committer | Justin Wernick <j.wernick@eyeo.com> | 2024-09-11 11:09:39 +0200 |
commit | 414ae1f4fbbe7dfe1f9d10f4da2145b88d0cd59d (patch) | |
tree | 2146f014bd30883679f82b857fe1f9820ac6810f | |
parent | b5707df9eeee2491c192bddb6ff8ae2520672662 (diff) |
Day 5
-rw-r--r-- | 2015/day5.exs | 33 | ||||
-rw-r--r-- | 2015/inputs/.gitkeep | 0 |
2 files changed, 33 insertions, 0 deletions
diff --git a/2015/day5.exs b/2015/day5.exs new file mode 100644 index 0000000..4e253c8 --- /dev/null +++ b/2015/day5.exs @@ -0,0 +1,33 @@ +santasList = File.stream!("inputs/day5.txt", [], :line) + +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}") diff --git a/2015/inputs/.gitkeep b/2015/inputs/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/2015/inputs/.gitkeep |