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 |
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 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 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 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 SpoilsOfFabric do | |
def count_overlaps(stream) do | |
stream | |
|> Stream.map(&cleanup/1) | |
|> Stream.map(&to_grid_positions/1) | |
|> Enum.reduce(%{}, &count_positions/2) | |
|> Enum.reduce(0, &count_overlaps/2) | |
end | |
def detect_sacred_fabric(stream) do |
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 InventoryManagement.Checksum do | |
def checksum(stream) do | |
stream | |
|> Stream.map(&String.trim/1) | |
|> Stream.map(&count_occurances/1) | |
|> Enum.reduce([two: 0, three: 0], &collect_each/2) | |
|> Enum.reduce(1, fn {_, val}, acc -> val * acc end) | |
end | |
defp collect_each([two: item_two, three: item_three], two: two, three: three) do |
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 ChronalCalibration do | |
def calc_result(stream), do: Enum.sum(stream) | |
def find_first_redundant(stream) do | |
Stream.cycle(stream) | |
|> Stream.scan({0, MapSet.new([0])}, &collect_step/2) | |
|> Stream.filter(&redundant?/1) | |
|> Stream.map(fn {elem, _} -> elem end) | |
|> Enum.take(1) | |
|> Enum.at(0) |
NewerOlder