change directory names

This commit is contained in:
Pim Kunis 2023-12-04 10:25:33 +01:00
parent 3cff0fc5cf
commit 78b8881016
90 changed files with 0 additions and 0 deletions

4
21/.formatter.exs Normal file
View file

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

17
21/lib/days/day1.ex Normal file
View file

@ -0,0 +1,17 @@
defmodule AOC.Day1 do
def part1 do
AOC.Util.input_integers(1, 1)
|> Enum.chunk_every(2, 1, :discard)
|> Enum.map(fn [x, y] -> y > x end)
|> Enum.count(& &1)
end
def part2 do
AOC.Util.input_integers(1, 1)
|> Enum.chunk_every(3, 1, :discard)
|> Enum.map(&Enum.sum/1)
|> Enum.chunk_every(2, 1, :discard)
|> Enum.map(fn [x, y] -> y > x end)
|> Enum.count(& &1)
end
end

27
21/lib/days/day2.ex Normal file
View file

@ -0,0 +1,27 @@
defmodule AOC.Day2 do
def parse_input do
AOC.Util.input_lines(2, 1)
|> Enum.map(fn l ->
[dir, amount] = String.split(l, " ")
{String.to_atom(dir), String.to_integer(amount)}
end)
end
def part1 do
parse_input()
|> Enum.reduce({0, 0}, fn
{:forward, amount}, {distance, depth} -> {distance + amount, depth}
{:down, amount}, {distance, depth} -> {distance, depth + amount}
{:up, amount}, {distance, depth} -> {distance, depth - amount}
end)
end
def part2 do
parse_input()
|> Enum.reduce({0, 0, 0}, fn
{:down, amount}, {distance, depth, aim} -> {distance, depth, aim + amount}
{:up, amount}, {distance, depth, aim} -> {distance, depth, aim - amount}
{:forward, amount}, {distance, depth, aim} -> {distance + amount, depth + aim * amount, aim}
end)
end
end

21
21/lib/util.ex Normal file
View file

@ -0,0 +1,21 @@
defmodule AOC.Util do
def input_file_name(day, input) do
Path.join([File.cwd!(), "inputs", "day#{day}", "input#{input}.txt"])
end
def input_file(day, input) do
input_file_name(day, input)
|> File.read!()
end
def input_lines(day, input) do
input_file_name(day, input)
|> File.stream!()
|> Enum.map(&String.trim/1)
end
def input_integers(day, input) do
input_lines(day, input)
|> Enum.map(&String.to_integer/1)
end
end

28
21/mix.exs Normal file
View file

@ -0,0 +1,28 @@
defmodule Aoc2021.MixProject do
use Mix.Project
def project do
[
app: :aoc2021,
version: "0.1.0",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# 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"}
]
end
end