Use Livebook to open this notebook and explore new ideas.
It is easy to get started, on your machine or the cloud.
# Advent 2024 - Day 3
```elixir
Mix.install([
{:kino, "~> 0.14.2"}
])
```
## Setup
```elixir
input = Kino.Input.textarea("Please paste your input file")
```
```elixir
instructions = input |> Kino.Input.read()
```
## Part 1
```elixir
validate = fn instructions ->
Regex.scan(~r/mul\((?<a>\d*),(?<b>\d*)\)/, instructions)
|> Enum.map(fn [_match, a, b] ->
String.to_integer(a) * String.to_integer(b)
end)
|> Enum.sum()
end
validate.(instructions)
```
## Part 2
```elixir
String.split("do()#{instructions}", "don't()")
|> Enum.map(fn instructions ->
[_ignore | rest] = String.split(instructions, "do()")
rest |> Enum.join()
end)
|> Enum.join()
|> then(fn instructions ->
validate.(instructions)
end)
```
See source