solve 2023 1.1
This commit is contained in:
parent
1a26e63ae9
commit
c5c6cf2582
13 changed files with 62 additions and 30 deletions
|
@ -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
|
||||
|
|
1
2023/elixir/.envrc
Normal file
1
2023/elixir/.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
export ADVENT_OF_CODE_SESSION=53616c7465645f5f18112545c7b5290961cf3f2c965e90c1b68415326ef1f99790e4dde4ef0cebc7abd120ea1b537aada76420516a0ceb883a722a84b81e7a02
|
3
2023/elixir/.gitignore
vendored
3
2023/elixir/.gitignore
vendored
|
@ -24,3 +24,6 @@ advent_of_code-*.tar
|
|||
|
||||
# Temporary files, for example, from tests.
|
||||
/tmp/
|
||||
|
||||
# Advent of Code input files
|
||||
/input
|
||||
|
|
1
2023/elixir/.iex.exs
Normal file
1
2023/elixir/.iex.exs
Normal file
|
@ -0,0 +1 @@
|
|||
import AOC.IEx
|
|
@ -1,2 +1,3 @@
|
|||
erlang 26.1.2
|
||||
elixir 1.15.7-otp-26
|
||||
direnv 2.33.0
|
||||
|
|
9
2023/elixir/config/config.exs
Normal file
9
2023/elixir/config/config.exs
Normal file
|
@ -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]
|
27
2023/elixir/lib/2023/1.ex
Normal file
27
2023/elixir/lib/2023/1.ex
Normal file
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
5
2023/elixir/mix.lock
Normal file
5
2023/elixir/mix.lock
Normal file
|
@ -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"},
|
||||
}
|
9
2023/elixir/test/2023/1_test.exs
Normal file
9
2023/elixir/test/2023/1_test.exs
Normal file
|
@ -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
|
|
@ -1,8 +0,0 @@
|
|||
defmodule AdventOfCodeTest do
|
||||
use ExUnit.Case
|
||||
doctest AdventOfCode
|
||||
|
||||
test "greets the world" do
|
||||
assert AdventOfCode.hello() == :world
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue