Advent of Code 2015 Day 19 Part 2
Mix.install([
{:kino_aoc, "~> 0.1"}
])
Get Inputs
{:ok, puzzle_input} =
KinoAOC.download_puzzle("2015", "19", System.fetch_env!("LB_SESSION"))
My answer
molecules =
puzzle_input
|> String.split("\n")
|> Enum.reverse()
|> hd()
count_str = fn molecules, str ->
Regex.scan(~r/#{str}/, molecules)
|> length()
end
count_str.("abcxxabcyy", "abc")
Regex.scan(~r/[A-Z]/, molecules)
|> length()
|> Kernel.-(count_str.(molecules, "Rn"))
|> Kernel.-(count_str.(molecules, "Ar"))
|> Kernel.-(2 * count_str.(molecules, "Y"))
|> Kernel.-(1)