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 Day17 do | |
def part1(num_steps), do: | |
insert(2017, num_steps, [], &List.insert_at/3) | |
|> Stream.chunk_every(2, 1) | |
|> Enum.find(&match?([2017, _], &1)) | |
|> Enum.at(1) | |
def part2(num_steps), do: | |
insert(50_000_000, num_steps, nil, | |
fn |
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 Day16 do | |
def part1(), do: | |
new_group() |> dance(instructions()) |> programs() |> Enum.join() | |
def part2(), do: | |
dances(1_000_000_000, instructions()) | |
defp dances(num_dances, instructions) do | |
{found_orders, cycle_start_pos, cycle_length} = search_cycle(instructions) | |
desired_pos = rem(num_dances - cycle_start_pos, cycle_length) |
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 Day15 do | |
require Bitwise | |
def part1(a, b), do: | |
judge(40_000_000, a, b, &rem(&1 * 16807, 2147483647), &rem(&1 * 48271, 2147483647)) | |
def part2(a, b), do: | |
judge(5_000_000, a, b, &find_next_factor(&1, 16807, 4), &find_next_factor(&1, 48271, 8)) | |
defp judge(steps, a, b, generator_a, generator_b, count \\ 0) |
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 Day14 do | |
def part1(input), do: | |
input |> grid_points(128) |> Enum.count() | |
def part2(input), do: | |
input |> groups(128) |> Enum.count() | |
defp groups(input, size), do: | |
input |> new_groupper(size) |> Stream.unfold(&pop_group/1) |
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 Day13 do | |
def part1(), do: | |
scanners() |> severities(0) |> Enum.sum() | |
def part2(), do: | |
0 | |
|> Stream.iterate(&(&1+1)) | |
|> Stream.transform(scanners(), &{[severities(&2, &1)], &2}) | |
|> Stream.take_while(&(not Enum.empty?(&1))) | |
|> Enum.count() |
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 | |
def part1(), do: | |
connections() |> group("0") |> Enum.count() | |
def part2(), do: | |
connections() |> all_groups() |> Enum.count() | |
defp connections(), do: | |
"input.txt" | |
|> File.stream!() |
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 | |
def part1(), do: | |
start_pos() | |
|> positions(directions()) | |
|> last() | |
|> distance(start_pos()) | |
def part2(), do: | |
start_pos() | |
|> positions(directions()) |
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 Day10 do | |
import Bitwise | |
def part1(input) do | |
lengths = input |> String.split(",") |> Enum.map(&String.to_integer/1) | |
[first, second | _rest] = round(initial_state(), lengths).elements | |
first * second | |
end | |
def part2(input), 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 Day9 do | |
def part1(), do: | |
score_groups(input()) | |
def part2(), do: | |
count_garbage(input()) | |
defp input() do | |
{groups, "\n"} = parse(zero_or_more(group()), File.read!("input.txt")) | |
groups |
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 Day8 do | |
def part1(), do: | |
instructions() | |
|> register_states() | |
|> last() | |
|> Map.values() | |
|> Enum.max() | |
def part2(), do: | |
instructions() |