Advent of Code 2024 - Day 3
Mix.install([
{:kino, "~> 0.14.2"}
])
Input
file_input = Kino.Input.file("day_3.txt")
file = Kino.Input.read(file_input)
path = Kino.Input.file_path(file.file_ref)
puzzle_input = File.read!(path)
Part One
Scan the corrupted memory for uncorrupted mul instructions. What do you get if you add up all of the results of the multiplications?
Regex.scan(~r{mul\((\d+),(\d+)\)}, puzzle_input)
|> Enum.map(fn [_, a, b] ->
String.to_integer(a) * String.to_integer(b)
end)
|> Enum.sum()
Part Two
There are two new instructions you’ll need to handle:
The do() instruction enables future mul instructions.
The don't() instruction disables future mul instructions.
Regex.scan(~r{do\(\)|don't\(\)|mul\((\d+),(\d+)\)}, puzzle_input)