Skip to content

Commit 3831536

Browse files
committed
Added Day 01
1 parent f545a16 commit 3831536

File tree

12 files changed

+137
-7
lines changed

12 files changed

+137
-7
lines changed

2025/.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test ~ aoc-2025:
3333
needs:
3434
- build ~ aoc-2025
3535
script:
36-
- mix deps.get && mix test --verbose
36+
- mix deps.get && mix test --all-warnings
3737
artifacts:
3838
when: always
3939
reports:

2025/apps/day00_elixir_template/benchmarks/puzzle_benchmarks.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ defmodule ElixirTemplate.Benchmark do
33
input = File.read!(Path.join(__DIR__, "../input/puzzle_input.txt"))
44

55
%{
6-
"elixir_template.task_1" => fn -> ElixirTemplate.task_1(input) end,
7-
"elixir_template.task_2" => fn -> ElixirTemplate.task_2(input) end
6+
"day00.elixir_template.task_1" => fn -> ElixirTemplate.task_1(input) end,
7+
"day00.elixir_template.task_2" => fn -> ElixirTemplate.task_2(input) end
88
}
99
end
1010
end
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
ExUnit.configure(
2-
formatters: [JUnitFormatter, ExUnit.CLIFormatter]
3-
)
4-
1+
ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter])
52
ExUnit.start()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
defmodule SecretEntrance.Benchmark do
2+
def jobs do
3+
input = File.read!(Path.join(__DIR__, "../input/puzzle_input.txt"))
4+
5+
%{
6+
"day01.secret_entrance.task_1" => fn -> SecretEntrance.task_1(input) end,
7+
"day01.secret_entrance.task_2" => fn -> SecretEntrance.task_2(input) end
8+
}
9+
end
10+
end
11+
12+
if System.get_env("AOC_COMBINED_BENCHMARK") do
13+
SecretEntrance.Benchmark.jobs()
14+
else
15+
Benchee.run(
16+
SecretEntrance.Benchmark.jobs(),
17+
print: [fast_warning: false],
18+
formatters: [{Benchee.Formatters.Console, extended_statistics: true}],
19+
warmup: 1,
20+
time: 2,
21+
memory_time: 2,
22+
reduction_time: 2
23+
)
24+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Example input>
38 Bytes
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
defmodule SecretEntrance.CLI do
2+
def main(args) do
3+
args |> parse_args |> read_file |> run
4+
end
5+
6+
defp parse_args(args) do
7+
{options, _, _} =
8+
OptionParser.parse(args, switches: [filename: :string], aliases: [f: :filename])
9+
10+
options[:filename]
11+
end
12+
13+
defp read_file(nil) do
14+
IO.puts("Usage: --filename <filename> or -f <filename>")
15+
System.halt(1)
16+
end
17+
18+
defp read_file(filename) do
19+
File.read!(filename)
20+
end
21+
22+
defp run(input) do
23+
IO.puts("Solution 1: #{SecretEntrance.task_1(input)}")
24+
IO.puts("Solution 2: #{SecretEntrance.task_2(input)}")
25+
end
26+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule SecretEntrance do
2+
@doc """
3+
Solution for task 1.
4+
"""
5+
def task_1(input) do
6+
String.length(input)
7+
end
8+
9+
@doc """
10+
Solution for task 2.
11+
"""
12+
def task_2(input) do
13+
String.length(input)
14+
end
15+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
defmodule SecretEntrance.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :day01_secret_entrance,
7+
version: "0.1.0",
8+
build_path: "../../_build",
9+
deps_path: "../../deps",
10+
lockfile: "../../mix.lock",
11+
elixir: "~> 1.19",
12+
start_permanent: Mix.env() == :prod,
13+
escript: [main_module: SecretEntrance.CLI, path: "../../_build/bin/secret_entrance"],
14+
deps: deps(),
15+
aliases: aliases()
16+
]
17+
end
18+
19+
# Run "mix help compile.app" to learn about applications.
20+
def application do
21+
[
22+
extra_applications: [:logger]
23+
]
24+
end
25+
26+
# Run "mix help deps" to learn about dependencies.
27+
defp deps do
28+
[
29+
{:benchee, "~> 1.0"},
30+
{:benchee_html, "~> 1.0"},
31+
{:junit_formatter, "~> 3.4", only: [:test]}
32+
]
33+
end
34+
35+
defp aliases do
36+
[
37+
bench: "run #{__DIR__}/benchmarks/puzzle_benchmarks.exs",
38+
solve: ["escript.build", &run_escript/1]
39+
]
40+
end
41+
42+
defp run_escript(_) do
43+
Mix.shell().cmd(
44+
"escript ../../_build/bin/secret_entrance -f #{__DIR__}/input/puzzle_input.txt"
45+
)
46+
end
47+
end

0 commit comments

Comments
 (0)