Advent of Code 2024 - Day 25
Mix.install([
{:kino_aoc, "~> 0.1.7"}
])
Section
{:ok, puzzle_input} =
KinoAOC.download_puzzle("2024", "25", System.fetch_env!("LB_AOC_SESSION"))
{locks, keys} =
puzzle_input
|> String.split("\n\n")
|> Enum.split_with(&match?("#" <> _, &1))
locks =
locks
|> Enum.map(fn str ->
str
|> String.split()
|> Enum.map(&String.to_charlist/1)
|> Enum.zip_with(&Function.identity/1)
|> Enum.map(&Enum.count(&1, fn char -> char == ?# end))
end)
keys =
keys
|> Enum.map(fn str ->
str
|> String.split()
|> Enum.map(&String.to_charlist/1)
|> Enum.zip_with(&Function.identity/1)
|> Enum.map(&Enum.count(&1, fn char -> char == ?# end))
end)
for lock <- locks,
key <- keys,
zipped = Enum.zip_with(lock, key, fn n1, n2 -> n1 + n2 end),
Enum.all?(zipped, & &1 <= 7),
reduce: 0,
do: (count -> count + 1)