Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Advent of Code 2015 Day 5 Part 1

2015_day5_part1.livemd

Advent of Code 2015 Day 5 Part 1

Mix.install([
  {:kino_aoc, "~> 0.1"}
])

Get Inputs

{:ok, puzzle_input} =
  KinoAOC.download_puzzle("2015", "5", System.fetch_env!("LB_SESSION"))

My answer

puzzle_input
|> String.split("\n")
|> Enum.count(fn word ->
  has_three_vowels =
    word
    |> String.codepoints()
    |> Enum.map(fn char ->
      ["a", "e", "i", "o", "u"]
      |> Enum.count(&(&1 == char))
    end)
    |> Enum.sum()
    |> Kernel.>(2)

  has_twice =
    Regex.run(~r/(.)\1/, word)
    |> then(&!is_nil(&1))

  no_ng =
    ["ab", "cd", "pq", "xy"]
    |> Enum.count(fn ng -> String.contains?(word, ng) end)
    |> Kernel.==(0)

  (has_three_vowels and has_twice and no_ng)
end)