Skip to content

Commit

Permalink
Solve 2024/05
Browse files Browse the repository at this point in the history
  • Loading branch information
code-shoily committed Dec 6, 2024
1 parent f2a2c8b commit 1202c33
Show file tree
Hide file tree
Showing 10 changed files with 2,546 additions and 31 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,35 @@ Note that you can call those commands independently and also set up pre-commit h

Note: All files mentioned above are autogenerated and are created by running `mix update_stats` task.

# :star: 291/450 :dart: 159 :trophy: 145.5/225 :dart: 79.5

| Day | [2015](/lib/2015) | [2016](/lib/2016) | [2017](/lib/2017) | [2018](/lib/2018) | [2019](/lib/2019) | [2020](/lib/2020) | [2021](/lib/2021) | [2022](/lib/2022) | [2023](/lib/2023) |
|:---:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
| :star2: | 48 | 22 | 34 | 15 | 15 | 44 | 24 | 45 | 44 |
| 1 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 2 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 3 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 4 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 5 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :2nd_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 6 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 7 | :1st_place_medal: | :1st_place_medal: | :2nd_place_medal: | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 8 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :2nd_place_medal: | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 9 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 10 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 11 | :1st_place_medal: | | :1st_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 12 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 13 | :1st_place_medal: | | :1st_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 14 | :1st_place_medal: | | :2nd_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 15 | :1st_place_medal: | | :1st_place_medal: | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 16 | :1st_place_medal: | | :1st_place_medal: | | | :2nd_place_medal: | :1st_place_medal: | | :1st_place_medal: |
| 17 | :1st_place_medal: | | :1st_place_medal: | | | | | | |
| 18 | :1st_place_medal: | | :2nd_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 19 | :1st_place_medal: | | | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 20 | :1st_place_medal: | | | | | :2nd_place_medal: | | :1st_place_medal: | |
| 21 | :1st_place_medal: | | | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |
| 22 | | | | | | :1st_place_medal: | | :2nd_place_medal: | :1st_place_medal: |
| 23 | :1st_place_medal: | | :2nd_place_medal: | | | :2nd_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 24 | :1st_place_medal: | | | | | :2nd_place_medal: | | :1st_place_medal: | :1st_place_medal: |
| 25 | :1st_place_medal: | | | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
# :star: 297/500 :dart: 203 :trophy: 148.5/250 :dart: 101.5

| Day | [2015](/lib/2015) | [2016](/lib/2016) | [2017](/lib/2017) | [2018](/lib/2018) | [2019](/lib/2019) | [2020](/lib/2020) | [2021](/lib/2021) | [2022](/lib/2022) | [2023](/lib/2023) | [2024](/lib/2024) |
|:---:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
| :star2: | 48 | 22 | 34 | 15 | 15 | 44 | 24 | 45 | 44 | 6 |
| 1 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 2 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |
| 3 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 4 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |
| 5 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :2nd_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: |
| 6 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |
| 7 | :1st_place_medal: | :1st_place_medal: | :2nd_place_medal: | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |
| 8 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :2nd_place_medal: | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 9 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |
| 10 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 11 | :1st_place_medal: | | :1st_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 12 | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 13 | :1st_place_medal: | | :1st_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 14 | :1st_place_medal: | | :2nd_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 15 | :1st_place_medal: | | :1st_place_medal: | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |
| 16 | :1st_place_medal: | | :1st_place_medal: | | | :2nd_place_medal: | :1st_place_medal: | | :1st_place_medal: | |
| 17 | :1st_place_medal: | | :1st_place_medal: | | | | | | | |
| 18 | :1st_place_medal: | | :2nd_place_medal: | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 19 | :1st_place_medal: | | | | | :1st_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 20 | :1st_place_medal: | | | | | :2nd_place_medal: | | :1st_place_medal: | | |
| 21 | :1st_place_medal: | | | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | | |
| 22 | | | | | | :1st_place_medal: | | :2nd_place_medal: | :1st_place_medal: | |
| 23 | :1st_place_medal: | | :2nd_place_medal: | | | :2nd_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 24 | :1st_place_medal: | | | | | :2nd_place_medal: | | :1st_place_medal: | :1st_place_medal: | |
| 25 | :1st_place_medal: | | | | | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | :1st_place_medal: | |


4 changes: 3 additions & 1 deletion lib/2024/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
[2015](/lib/2015) | [2016](/lib/2016) | [2017](/lib/2017) | [2018](/lib/2018) | [2019](/lib/2019) | [2020](/lib/2020) | [2021](/lib/2021) | [2022](/lib/2022) | [2023](/lib/2023) | 2024


## :trophy: 2/50
## :trophy: 6/50

| Day | Problem Page | Status | Difficulty | Solution Page | Test Page | Tags |
| :---: | :------: | :---: | :---: | :---: | :---: | :---: |
| 1 | [Historian Hysteria](https://adventofcode.com/2024/day/1) | :1st_place_medal: | :snowflake: | [day_01.ex](/lib/2024/day_01.ex) | [day_01_test.exs](/test/2024/day_01_test.exs) | [list](/wiki/tags.md#list) |
| 3 | [Mull It Over](https://adventofcode.com/2024/day/3) | :1st_place_medal: | :snowflake: | [day_03.ex](/lib/2024/day_03.ex) | [day_03_test.exs](/test/2024/day_03_test.exs) | [regex](/wiki/tags.md#regex), [fsm](/wiki/tags.md#fsm) |
| 5 | [Print Queue](https://adventofcode.com/2024/day/5) | :1st_place_medal: | :snowflake: | [day_05.ex](/lib/2024/day_05.ex) | [day_05_test.exs](/test/2024/day_05_test.exs) | [set](/wiki/tags.md#set), [sort](/wiki/tags.md#sort) |

40 changes: 40 additions & 0 deletions lib/2024/day_01.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule AdventOfCode.Y2024.Day01 do
@moduledoc """
--- Day 1: Historian Hysteria ---
Problem Link: https://adventofcode.com/2024/day/1
Difficulty: xs
Tags: list
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}

def input, do: InputReader.read_from_file(2024, 1)

def run(input \\ input()) do
input = parse(input)

{run_1(input), run_2(input)}
end

defp run_1({left_list, right_list, _}) do
for {left, right} <- Enum.zip(left_list, right_list), reduce: 0 do
acc -> acc + abs(left - right)
end
end

defp run_2({left_list, _, tally}) do
for id_value <- left_list, reduce: 0 do
acc -> acc + id_value * Map.get(tally, id_value, 0)
end
end

def parse(data \\ input()) do
{left, right} =
for line <- Transformers.lines(data), reduce: {[], []} do
{left_list, right_list} ->
[left, right] = String.split(line)
{[String.to_integer(left) | left_list], [String.to_integer(right) | right_list]}
end

{Enum.sort(left), Enum.sort(right), Enum.frequencies(right)}
end
end
54 changes: 54 additions & 0 deletions lib/2024/day_05.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
defmodule AdventOfCode.Y2024.Day05 do
@moduledoc """
--- Day 5: Print Queue ---
Problem Link: https://adventofcode.com/2024/day/5
Difficulty: xs
Tags: set sort
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}

def input, do: InputReader.read_from_file(2024, 5)

def run(input \\ input()) do
input = parse(input)

{run_1(input), run_2(input)}
end

defp run_1(input) do
input
|> Enum.filter(fn {a, b} -> a == b end)
|> Enum.map(fn {a, _} -> a |> Enum.at(div(length(a), 2)) end)
|> Enum.sum()
end

defp run_2(input) do
input
|> Enum.filter(fn {a, b} -> a != b end)
|> Enum.map(fn {_, b} -> b |> Enum.at(div(length(b), 2)) end)
|> Enum.sum()
end

def parse(data \\ input()) do
[deps, updates] = Transformers.sections(data)
given_sorted_pair({parse_deps(deps), parse_updates(updates)})
end

defp parse_deps(deps) do
for line <- Transformers.lines(deps),
into: MapSet.new(),
do: String.split(line, "|") |> Enum.map(&String.to_integer/1) |> List.to_tuple()
end

defp parse_updates(updates) do
for line <- Transformers.lines(updates) do
for update <- String.split(line, ","), do: String.to_integer(update)
end
end

defp given_sorted_pair({deps, updates}) do
for update <- updates do
{update, Enum.sort(update, &({&1, &2} in deps))}
end
end
end
Loading

0 comments on commit 1202c33

Please sign in to comment.