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
21/lib/days

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