diff --git a/2023/README.md b/2023/README.md index 66ce7ba..5fcd2ac 100644 --- a/2023/README.md +++ b/2023/README.md @@ -2,8 +2,11 @@ | S | M | T | W | T | F | S | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | -| | | | | | 1 | 2 | +| | | | | | [1] | 2 | | 3 | 4 | 5 | 6 | 7 | 8 | 9 | | 10 | 11 | 12 | 13 | 14 | 15 | 16 | | 17 | 18 | 19 | 20 | 21 | 22 | 23 | | 24 | 25 | | | | | | + + +[1]: ./elixir/lib/2023/1.ex diff --git a/2023/elixir/.envrc b/2023/elixir/.envrc new file mode 100644 index 0000000..24bb1b6 --- /dev/null +++ b/2023/elixir/.envrc @@ -0,0 +1 @@ +export ADVENT_OF_CODE_SESSION=53616c7465645f5f18112545c7b5290961cf3f2c965e90c1b68415326ef1f99790e4dde4ef0cebc7abd120ea1b537aada76420516a0ceb883a722a84b81e7a02 diff --git a/2023/elixir/.gitignore b/2023/elixir/.gitignore index 44fe69c..93c98b2 100644 --- a/2023/elixir/.gitignore +++ b/2023/elixir/.gitignore @@ -24,3 +24,6 @@ advent_of_code-*.tar # Temporary files, for example, from tests. /tmp/ + +# Advent of Code input files +/input diff --git a/2023/elixir/.iex.exs b/2023/elixir/.iex.exs new file mode 100644 index 0000000..795d6b6 --- /dev/null +++ b/2023/elixir/.iex.exs @@ -0,0 +1 @@ +import AOC.IEx diff --git a/2023/elixir/.tool-versions b/2023/elixir/.tool-versions index ff52406..87ae38b 100644 --- a/2023/elixir/.tool-versions +++ b/2023/elixir/.tool-versions @@ -1,2 +1,3 @@ erlang 26.1.2 elixir 1.15.7-otp-26 +direnv 2.33.0 diff --git a/2023/elixir/config/config.exs b/2023/elixir/config/config.exs new file mode 100644 index 0000000..536c8e8 --- /dev/null +++ b/2023/elixir/config/config.exs @@ -0,0 +1,9 @@ +import Config + +config :advent_of_code_utils, + auto_compile?: true, + time_calls?: true, + gen_tests?: true, + session: System.get_env("ADVENT_OF_CODE_SESSION") + +config :iex, inspect: [charlists: :as_lists] diff --git a/2023/elixir/lib/2023/1.ex b/2023/elixir/lib/2023/1.ex new file mode 100644 index 0000000..9fc0995 --- /dev/null +++ b/2023/elixir/lib/2023/1.ex @@ -0,0 +1,27 @@ +import AOC + +aoc 2023, 1 do + def p1(input) do + input + |> String.split("\n") + |> Stream.map(&get_first_and_last_numbers_as_number/1) + |> Enum.sum() + end + + def p2(_input) do + end + + def get_first_and_last_numbers_as_number(str) do + trimmed = + str + |> String.replace(~r/^[^\d]+/, "") + |> String.reverse() + |> String.replace(~r/^[^\d]+/, "") + |> String.reverse() + + first = String.first(trimmed) + last = String.last(trimmed) + + String.to_integer(first <> last) + end +end diff --git a/2023/elixir/lib/advent_of_code.ex b/2023/elixir/lib/advent_of_code.ex deleted file mode 100644 index 33601c2..0000000 --- a/2023/elixir/lib/advent_of_code.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule AdventOfCode do - @moduledoc """ - Documentation for `AdventOfCode`. - """ - - @doc """ - Hello world. - - ## Examples - - iex> AdventOfCode.hello() - :world - - """ - def hello do - :world - end -end diff --git a/2023/elixir/mix.exs b/2023/elixir/mix.exs index 0fa234e..dc60627 100644 --- a/2023/elixir/mix.exs +++ b/2023/elixir/mix.exs @@ -21,8 +21,7 @@ defmodule AdventOfCode.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - # {:dep_from_hexpm, "~> 0.3.0"}, - # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + {:advent_of_code_utils, "~> 4.0.0"} ] end end diff --git a/2023/elixir/mix.lock b/2023/elixir/mix.lock new file mode 100644 index 0000000..77df8e0 --- /dev/null +++ b/2023/elixir/mix.lock @@ -0,0 +1,5 @@ +%{ + "advent_of_code_utils": {:hex, :advent_of_code_utils, "4.0.0", "28df8cde0d6cccf95b72880ab89b00e1cb7c0492164bbf537bdf229c0953f7aa", [:mix], [{:floki, "~> 0.34", [hex: :floki, repo: "hexpm", optional: false]}, {:tz, "~> 0.26", [hex: :tz, repo: "hexpm", optional: false]}], "hexpm", "6f44c1f5b901e6a5bd7561361f3441ee7fa4ee67ea28d7fc3b2df29303d80ff4"}, + "floki": {:hex, :floki, "0.35.2", "87f8c75ed8654b9635b311774308b2760b47e9a579dabf2e4d5f1e1d42c39e0b", [:mix], [], "hexpm", "6b05289a8e9eac475f644f09c2e4ba7e19201fd002b89c28c1293e7bd16773d9"}, + "tz": {:hex, :tz, "0.26.2", "a40e4bb223344c6fc7b74dda25df1f26b88a30db23fa6e55de843bd79148ccdb", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:mint, "~> 1.5", [hex: :mint, repo: "hexpm", optional: true]}], "hexpm", "224b0618dd1e032778a094040bc710ef9aff6e2fa8fffc2716299486f27b9e68"}, +} diff --git a/2023/elixir/test/2023/1_test.exs b/2023/elixir/test/2023/1_test.exs new file mode 100644 index 0000000..291e118 --- /dev/null +++ b/2023/elixir/test/2023/1_test.exs @@ -0,0 +1,9 @@ +import AOC + +aoc_test 2023, 1, async: true do + describe "p1" do + test "works for the example input" do + assert p1(example_string()) == 142 + end + end +end diff --git a/2023/elixir/test/advent_of_code_test.exs b/2023/elixir/test/advent_of_code_test.exs deleted file mode 100644 index 8a98262..0000000 --- a/2023/elixir/test/advent_of_code_test.exs +++ /dev/null @@ -1,8 +0,0 @@ -defmodule AdventOfCodeTest do - use ExUnit.Case - doctest AdventOfCode - - test "greets the world" do - assert AdventOfCode.hello() == :world - end -end diff --git a/README.md b/README.md index 0c5cc7b..602d1ec 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 1. [2020] **17/50** 🌟 1. [2021] **43/50** 🌟 1. [2022] **14/50** 🌟 -1. [2023] +1. [2023] **1/50** 🌟 [2015]: ./2015 [2017]: ./2017