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

Advent of Code 2015 Day 5 Part 2

2015_day5_part2.livemd

Advent of Code 2015 Day 5 Part 2

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_repeat =
    Regex.run(~r/(.{2,}).*\1/, word)
    |> then(&!is_nil(&1))

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

  (has_repeat and has_between)
end)