Solutions for Advent of Code in Elixir.
Inspired from Advent of Code Rust.
Important
DON'T make the advent of code puzzle inputs public. Do one of the following:
- Make your repository private.
- Or add those lines to your
.gitignorefile:
input.txt
example-*.txt| Year | Day | Part 1 | Part 2 |
|---|
- Use this link to create your repository.
- Clone the repository to your computer.
- Use
mix aoc.scaffoldand start coding!!!
Important
Make sure not to use the Logger module for logging, some tasks like aoc.test suppress IO output, this does work for the Logger module, but then the output wont be in the right order...
You can pass arguments in three different ways.
-
As key value pair:
--<key>=<value> -
As key only, will set the value to
true:--<key> -
As value only, this will try to match values to a key:
<value>E.g. if you pass
2025will know it is ayearbecause it has 4 digits and is in range from2000to2099. Days can also be recognized because they are 1 or 2 digits and are in range from1to25.
Tip
You can get more information about arguments and more examples by running: mix help aoc.<command>.
# example: mix aoc.scaffold 2025 1
mix aoc.scaffold --year=<year> --day=<day>
# output:
# Created elixir file: lib/bin/Y2025/D01.ex
# Created input file: puzzles/Y2025/D01/input.txt
# Created example file: puzzles/Y2025/D01/example-1.txt
# Created .keep file: data/Y2025/D01/.keepTip
You can add more examples by adding an example file with a different number, something like this: example-2.txt.
You can only use integers, no letters...
Tip
To specify wich example input your test should use you can change the example option in the generated elixir file.
Read the comments.
defmodule Bin.Y2025.D01 do
def part_one(_input) do
# Code for part one
nil
end
def part_two(_input) do
# Code for part two
nil
end
def tests do
[
# - `part`: Is the atom of the function that will be called from the test.
# - `result`: Is the expected result returned from the function.
# - `example`: Specifies which example file to use (../example-<example>.txt).
[part: :part_one, result: nil, example: 1],
[part: :part_two, result: nil, example: 1],
# Feel free to add more tests here.
]
end
end# example: mix aoc.test 2025 1
mix aoc.test --year=<year> --day=<day>
# output:
# Testing lib/bin/Y2025/D01.ex
# ----------------------------
# Testing part_one
# Part One succeded in 0.003ms
# Testing part_two
# Part One succeded in 0.001msThis task will run all tests specified in the tests/0 function of the solution file.
# example: mix aoc.solve 2025 1
mix aoc.solve --year=<year> --day=<day>
# output:
# Solve part one.
# Solve part two.
# -------------
# Part One (0.002ms): ✖ # function returned nil
# Part Two (0.002ms): 42This task will run part one and two, and display the results.
# example: mix aoc.bench 2025 1
mix aoc.bench --year=2025 --day=1
# output:
# Benching lib/bin/Y2025/D01.ex
# -----------------------------
# part_one returned nil, skipping.
# part_two: 0.001ms (5)