From 414ae1f4fbbe7dfe1f9d10f4da2145b88d0cd59d Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Wed, 11 Sep 2024 11:09:39 +0200 Subject: Day 5 --- 2015/day5.exs | 33 +++++++++++++++++++++++++++++++++ 2015/inputs/.gitkeep | 0 2 files changed, 33 insertions(+) create mode 100644 2015/day5.exs create mode 100644 2015/inputs/.gitkeep 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 -- cgit v1.2.3