Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Advent of Code

template.livemd

Advent of Code

Mix.install([
  {:smaoc, git: "https://github.com/nettinho/smaoc"}
])

Solutions

Root section to execute each day independently

Day 1

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day1

defmodule solution_module do
  defp parse_input(input) do
    input
    |> String.split("\n")
    |> Enum.reject(&(&1 == ""))
    |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 2

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day2

defmodule solution_module do
  defp parse_input(input) do
    input
    |> String.split("\n")
    |> Enum.reject(&amp;(&amp;1 == ""))
    |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = 2
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 3

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day3

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 4

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day4

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 5

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day5

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 6

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day6

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 7

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day7

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 8

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day8

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 9

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day9

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 10

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day10

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 11

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day11

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 12

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day12

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 13

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day13

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 14

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day14

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 15

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day15

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 16

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day16

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 17

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day17

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 18

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day18

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 19

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day19

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 20

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day20

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 21

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day21

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 22

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day22

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 23

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day23

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 24

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day24

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})

Day 25

solution_module = Smaoc.Solution
solution_module = Smaoc.Solution.Day25

defmodule solution_module do
  defp parse_input(input) do
    input |> String.split("\n") |> Enum.reject(&amp;(&amp;1 == "")) |> Enum.count()
  end

  def solve(:part1, input) do
    parse_input(input)
  end

  def solve(:part2, input) do
    parse_input(input)
  end
end

year = nil
day = nil
run_config = ["part1", "example"]
inputs = %{"puzzle" => "", "example" => ""}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})