This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule ReposeRecord do | |
| def calc_part1(logs_str) do | |
| logs_str | |
| |> String.split("\n", trim: true) | |
| |> sort_logs() | |
| |> Enum.map(&parse_event/1) | |
| |> chart_event_timeline() | |
| |> gather_guard_stats() | |
| |> calc_weakest_guards_most_slept_metric() | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule AlchemicalReduction do | |
| @doc """ | |
| For example, again using the polymer dabAcCaCBAcCcaDA from above: | |
| * Removing all A/a units produces dbcCCBcCcD. Fully reacting this polymer produces dbCBcD, which has length 6. | |
| * Removing all B/b units produces daAcCaCAcCcaDA. Fully reacting this polymer produces daCAcaDA, which has length 8. | |
| * Removing all C/c units produces dabAaBAaDA. Fully reacting this polymer produces daDA, which has length 4. | |
| * Removing all D/d units produces abAcCaCBAcCcaA. Fully reacting this polymer produces abCBAc, which has length 6. | |
| In this example, removing all C/c units was best, producing the answer 4. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule ChronalCoordinates do | |
| def calc_part2(str_coords, threshold) do | |
| coords = parse_coords(str_coords) | |
| {bound_x, bound_y} = find_boundaries(coords) | |
| reduce_grid({bound_x, bound_y}, 0, fn x, y, acc -> | |
| sum = Enum.reduce(coords, 0, &sum_of_distances(&1, &2, {x, y})) | |
| if sum < threshold, do: acc + 1, else: acc | |
| end) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day11 do | |
| @ets_table_name :day11_max_powers | |
| @grid {300, 300} | |
| @doc """ | |
| Initializes required partial sum caching mechanism (ets table). | |
| """ | |
| def start() do | |
| :ets.new(@ets_table_name, [:set, :named_table, read_concurrency: true]) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day12 do | |
| @initial_state "##.#....#..#......#..######..#.####.....#......##.##.##...#..#....#.#.##..##.##.#.#..#.#....#.#..#.#" | |
| @doc """ | |
| Resolves part#1. | |
| """ | |
| @spec index_sum_after_iteration(pos_integer) :: pos_integer | |
| def index_sum_after_iteration(iteration \\ 20) do | |
| last_state = iterate(@initial_state, iteration) | |
| to_sum(last_state) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day11 do | |
| @ets_table_name :day11_max_powers | |
| @grid {300, 300} | |
| @doc """ | |
| Initializes required partial sum caching mechanism (ets table). | |
| """ | |
| def start() do | |
| :ets.new(@ets_table_name, [:set, :named_table, read_concurrency: true]) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule UI.Helpers do | |
| @moduledoc """ | |
| Provides common helpers and js commands to work with | |
| UI components. | |
| """ | |
| @doc """ | |
| Utility function that pipes into `assigns` and | |
| helps with class concatenation inside live_views |
OlderNewer