Day X - Advent of Code 2024
Mix.install([:kino, :benchee])
Links
Prompt
— Day X: TBD —
Part One prompt
QUESTION ONE?
To begin, get your puzzle input.
— Part Two —
Part Two prompt
QUESTION TWO?
Although it hasn’t changed, you can still get your puzzle input.
Input
input = Kino.Input.textarea("Please paste your input file:")
input = input |> Kino.Input.read()
""
Solution
defmodule Day01 do
defdelegate parse(input), to: __MODULE__.Input
def part1(input) do
input
|> parse()
|> Enum.map(& &1)
end
def part2(input) do
input
|> parse()
|> Enum.map(& &1)
end
defmodule Input do
def parse(input) when is_binary(input) do
input
|> String.splitter("\n", trim: true)
|> parse()
end
def parse(input) do
Stream.map(input, &parse_line/1)
end
def parse_line(line) do
line
# |> String.split(["-", ","])
# |> Enum.map(&String.to_integer/1)
end
end
end
{:module, Day01, <<70, 79, 82, 49, 0, 0, 8, ...>>,
{:module, Day01.Input, <<70, 79, 82, ...>>, {:parse_line, 1}}}
QUESTION ONE?
Your puzzle answer was answer one
.
Day01.part1(input)
[""]
QUESTION TWO?
Your puzzle answer was answer two
.
Day01.part2(input)
[""]
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
Tests
ExUnit.start(auto_run: false)
defmodule Day01Test do
use ExUnit.Case, async: false
setup_all do
[
input: ""
]
end
describe "part1/1" do
test "returns expected value", %{input: input} do
assert Day01.part1(input) == [""]
end
end
describe "part2/1" do
test "returns expected value", %{input: input} do
assert Day01.part2(input) == [""]
end
end
end
ExUnit.run()
..
Finished in 0.00 seconds (0.00s async, 0.00s sync)
2 tests, 0 failures
Randomized with seed 162351
%{excluded: 0, failures: 0, skipped: 0, total: 2}
Benchmarking
defmodule Benchmarking do
# https://github.com/bencheeorg/benchee
def run(input) do
Benchee.run(
%{
"Part 1" => fn -> Day01.part1(input) end,
"Part 2" => fn -> Day01.part2(input) end
},
memory_time: 2,
reduction_time: 2
)
nil
end
end
nil
Benchmarking.run(input)