Compare commits

..

No commits in common. "e9a505ebd3463db582119d7cc71ec9acf7aa5e29" and "a3a7df74b8ffea0b43eb053e5b8e3b051412d26a" have entirely different histories.

6 changed files with 0 additions and 399 deletions

View file

@ -1,58 +0,0 @@
%cv -> xz
%kt -> qx, rz
%cb -> kt
%pl -> sf, db
%zd -> ln, gf
%bf -> qx, pf
%xz -> jd
%xm -> db
%vz -> cr, vc
%qq -> qm, gf
&xn -> th
%nn -> ff, db
%gx -> cd
&qn -> th
%qk -> vc
&xf -> th
%qj -> xm, db
%fn -> pr, gf
%sf -> bp
%jd -> qx, vm
%mc -> ds, db
%tj -> lc, gf
%jz -> qj, db
%sb -> ks, vc
%ln -> gf, qq
%bx -> qx, qp
broadcaster -> sr, ch, hd, bx
%ch -> db, mc
%ds -> cc
&qx -> cb, cv, bx, xz, vm, zl
%bp -> db, jz
&zl -> th
%vl -> gf, fj
&db -> ff, ds, sf, ch, cc, xf
&th -> rx
%cr -> gx, vc
%sr -> gf, vl
%lr -> sb
%hv -> lr
%cl -> qx, bf
%lc -> gf, fn
%pm -> vc, qk
%cc -> nn
%gm -> tj, gf
%vm -> cl
%ff -> pl
%qp -> cb, qx
%pf -> qx
&vc -> lr, hd, ks, qn, gx, nh, hv
%qm -> gm
%nh -> hv
%rz -> qx, cv
%ks -> vz
%fj -> zd
&gf -> fj, qm, xn, sr
%pr -> gf
%cd -> pm, vc
%hd -> vc, nh

View file

@ -1,5 +0,0 @@
broadcaster -> a, b, c
%a -> b
%b -> c
%c -> inv
&inv -> a

View file

@ -1,131 +0,0 @@
...................................................................................................................................
...................#.....#.....#.#.............#.#......#.......................#......#.......#......#...#...#.##..........##.....
......#......#.....#....#........#...............#..........................#................#...........#...#......#.....#.##.#...
..#.........#......#........##..##.#............#.#.#.#...................##....#......#.#............#...........#................
.#...............#....###.#....#...........#........##..............................#...............##.............#....#..........
............#.............##..#.#.....#..........#...#....................###...#.......#...........#.......##.#.........#.........
.................#..........#..#..#.....##..#........#..........#............#...##.#..............#.....#.........#....#..#.......
...#.......#..........#..#......###............#...#.#......................#.....#........###.#.............#..#....#..........#..
.................#...#........................................................#.#..................##...#.#.#....#...##..........#.
....#..........#...##...#...........#...........#................................#..#.............#.#...........#....#........#....
.....#....##...#........#......#.#..............#..........#......#..............#.......#...................#.......#...##..#...#.
......#...#.#....#...............#............#.....................#................#...###.#...#..........#.##...#...............
.....##..#............#..#.........#..#....#...............#..............................#.#.......................#............#.
.........##.....#.....#.........#.....#....#...............#.##.#....................#........................#..#..#...........#..
......#.##.............#......#.##.............................#......#..#..........#....#.#.......#...#.#...#.......#.#........#..
...................#..........#...........#.................#......#.......#..................#.....#...........#.#...#............
.....#.........##........#.........#.#.#.##..............#....#..........##.............###.##.....#......##.##.#...............#..
.#..#.....#...#..#......#..........................................#..........................#.....#......#.......................
.....#.#....#..........#............#.....##.................#................................#.##..#...........#............#.....
............#.......#...#.#......#.............................#...............................#..........#................#.....#.
.......#.....##..........##.#.........#...............................#......#.#..........................#......#......##.....#...
......#.#.......#..#..#..#............................##.#....##..........#...............#.......#.............##.....##..........
................#..#.........#.....#...........#...##.#.....#.......#......#...............#..#......##........#...#.#.............
.#............#..#.#.#....#....#.............................#.........#...........#................#....#...#....#...#.#...#......
.................#......#......##..............#.........#........#.........#...#....#............#.#..#...................#..##...
........#..........#..........................##..#....#...............................................#......#...........##..#....
........#.#.#..........#...#....................#....#..#....#.........#...#..#.................#......#..##......#..........#.....
...............#..................#.................................#..#....#..#..#...................#.......#............#.......
.#.#..............#......#.............................................#..............##....................#...........#......#.#.
.#.........#.....#............#...............#...........#.......#......#........................#...#..................#.........
......#.........#....#.....................#.#..................#....#....#.....###..#.#.............#..#..........................
...#....#................................#.....#.#...........#.................#.................................#.......#.....#.#.
...#...#..##...........#..............#....................#.........#.#....#....##..................#....#...#....................
......#..........#........#...........................##........#.#.....#.....#.......#...............#.......#....................
.......#..........##..#.#..........................#.#........#.#...........#...........#....#.........#..................#.#......
....................#....................#.........#...#......#.......#.......##...................................................
..........#............#..........#........#...........#......................#..........................##.#..#.........#...#.....
......#.....#.....................#.##.........#...#............#.#...........#...#.#............#.........##......#..........#....
.....#..........#.....#..............#.......#..##...........#.............#..#....#...#.......................##...........##...#.
.#..........#...#....................#...#......#..#.................#........#..........#...#...#..#.........#.........#....#.....
......#......#.....................#.......#.....#.........................##............#.#..##.................#...#...###.......
.......#.......#...................#..........#...#.....#......................#......##.....#.................#.............#.....
......#.....#..#..................#............................#....#.#..#..##.....................................................
.....#..#....#..#.#...............#......#.............#..#...........#.....#....#..#......#.#.....................##.#............
....#.......#..#.........#........#....#.#..................##......#..........#........................#.............#.....#......
.#.....#......#........................#..#..............................#..........#.......#.......##...#...........#.............
...........................#.........#....##.....#.#....#...###...######...#.#......#...............#..........................##..
..#......#................#.#......#.#.............#..#......#....#..#..#..#.........................##.........................#..
...#........#.........#.##..............................##.#....#.......#.......#.......................#.#.#...............#....#.
.......#..#.......................#..............#..........................#.#.....#.....#............#..............#..#.#.....#.
..#.........................##......................#.........#.#.#.#........#.................#.....#..#.#........................
..................#.......#.................#.#...................#.......#.#...........#......##...........................#......
.......................#.#.....##...#.#.....#...#...#.##...#.............#.....................##.##...............................
..#...............#.....#......#.....###.......................#............#.............#.#.....#.#.#............................
.......#...................#......#...#....................#.#...............#..........................#..#................#..#...
...........................#..........##..#..........#................................#..##..#.......##....#....#...........#......
...##.............#...##.....#.......#...............#.....###..#.........#.............#....#........#...#.....#.#................
.#...................#...##...........#............##........................#....#....#.....#........#......#...................#.
..............#.#..........#................................#...........#..#..............##..##...#.......#.......#..#..........#.
...............#........#........#..............#....#.........#.......#..........#.......#.#............#......#.#...#.........#..
.........#.......###...#.#...#..................#..#.......#...##...#.....##............#..#.......#...............................
............#......#.......................#..........#...#........#.#.......#....................#......#......#....#....#........
.........##.....#.......................................#...........#........................#.........#...........................
..........##.........#.....#.......#.................##..#.#......##...............#....#...#..#..#...##..#.##.#.....#.#.#.........
.......................#..............#......##.#.#.#...................##....##........#....#.....................#...............
.................................................................S.................................................................
.....#............#................#..###............#..##....#.#......#...........#..........#...#................................
...........#.......#...#.........#....#........#..#................#.........#.#......................#....#....#.........#.#......
................#..#........................#..#................#......#..#.......#...........##...#...............#...............
............#....#...#.....#.##.............#.#..............#.#...#........#...........#..#...##.........................#........
.#.........##.#..#...#.....#.#....##.#.#.....#.................#...#.........................#............#.#.#....#...............
.#...........#.#..........#......................#...#......##............#....................#......##.......#........#..........
..#......................#.#.............#..#.........................#........##.#.#...#..#.#...................#.................
.........................................#.#...#.#............#.............#...........#.#..#.#.#.......#.#.....#..#..............
....#........................#........#...#...........#..#..................##.#.#...........#....#.#......#...................#.#.
......#..........#.......##....#..........#.....#.............#.#......#..........#....#...........#.......#.......#...........#...
...#............#........#..#...........#........#..###.....#..#..........#...........#.........#.........#...##.###............##.
.......#........#....#.#.#.........#..#...............#..#........#.......#.................#.......#...#........#..............#..
.......................#............#.....#......#............#....#.....#.#..#..........#.......#...#........#..........#.........
...#..............#...................#.....#.........#....#.........#.......#.#.............##........#....#...#..................
..........#..........#......#.............#....................#..#.......#.#.#....##...#.#................................#.......
..#...........................#.......................................#....#..........#....................#................#....#.
......................#.#...............#.......#.........#....##.................#......#..........#....................##......#.
.........#...#............#...............##.....#......#..#........#.....#...#............#....................................#..
......##..#.#...........#..#...........###.....#........................##.....................#........#..........................
............#...............#....#..#..............#.................#......#.#..#..........#..................................#...
.............#.##...................................#.........##...#.....................................#.................#.#...#.
.#...........................#............#............#.####..........................#.#...#.#.....#...........#.................
.....#...........#.#.................#....#....#....##.#.....#.....#...#............##...#.#....................#.#.#..#..#..#.....
........#.#..#..#...........#.........#..#.....#.##.#........#......................#........#.....##...........#......#...........
............#..#................#......#.#.#............#...#...........#....#..#..............................................#.#.
......#...#............................................................#...#................#.##............#.....#....#.......#...
..#..........#...#.....................#............#........#.......#.##....#...#.............#........................##......#..
..#....#.#..........................#.#......#.......#..........#......#..........#......#.....#...............#.##.....#...#......
.................#......##........#....................#..#.......#........#.......#.#.....................#...................#...
....####..............##...........#.........#....#......#.....................#.#...#.....#.#...............#.#...................
......#.....#.............................#.........#..#..#.....#.#............##......##..#............#..#....#......#...#...###.
.#........#............#...#..............#..............##....#......#...#.#.#.........#..#.#........#...........#...##....#......
.......#......#..#.....#.....................#....#..#..............#...............#....................#....#...##..#.......#.##.
........#.........#....###...#...........#..........#..........#....#....#...........#......#...........#...#..........#.......#...
....#...........#.......#...##.........#...#...#...#......#..............#......................................#.......##....##...
.....##..#..........#..#...#.................##.........................#..#............................#......#.#..............#..
.#.#.##...............#.........#...............................#..#....##.#......#...#..#.............#................#..........
.....................#....#.....#............#..#.#.....#...........#......#..........................#................###...#.....
.#.......#..#.....................##..........#.............................##......#.................#...............#.....#.##...
..#..............#...#.#........................#..#..................##.......#..............##.#..................##.............
............#..........#.................................................#......#..#.#.........#...#....................#....#.....
.......#.................#.....................#.....#..##....................#.........................#........#...#....#.##.....
.#..............###.....#.........#...................#....#............#..#.................#......##....##.#.#.........#.........
..................#.#.................................#.......##..#..#.#..#.#.#.........................#...#..........#...#.......
.......##...#...##...#.............................................#...#.........................#..........##.....###...#.....#...
.......#........#..#...#....#..........#.#........#........#......#..#...................#........#.#....##.#......#.#.........#...
..#....#..........#.#..#...........#.....................#..#...#.#...#..#..#..............#......#..#.......#..##..#..............
..........#.........#...##..........#...#..........................#.........................#.................#.....#.....#.....#.
............#......#..#...............#.....#..................#.......#....................#...#....#...#......#........#...#.....
.##........................#....##.#....................#.....#...........#...........#...#........#...#..........#..#......#......
...#....................#...............#...............................#....................................#....#.#..........#...
......................#.............##....#.............#....#..#.#.......#............##............#.#.##.........#......#...#...
..#..#..........#.##.........#......##...#......................#...................#.................#..................##........
.........#............##.#....#......#....##.#.#..........#.......#...#.............#........................#..........#..........
.....#..#............#..............#..#..............................#................#.....#...........................#.#.#.....
........#..#.##...#..#..##.#....#..........##.................##..#...............#.#....#..........#.........##..##...............
..........#..........#....#..#.............#.................#.....#..............#...........##......##...........................
.#....##...#...........#.................##....................................#..#..........................#...........#.........
.............................#............#..#......#...........................##..............#.#...#............#.......##.#....
....#...........#..##....##.#......##.....##........#..##.................#.........................#.......##.#.#...#...#.........
..........#...#............#....#....#..##.....#.........#........................#..............#.......................#.....#...
..#.....#....#...#..##.#..........#.#.....#...............#..............#.##..#...#..........#.....#.#.........##.##.....#......#.
......#....#.........#............#.....................##................#..#.............#..............#....#.............#.....
.......#...........#......#........#.............#...#......#................#.#.#........#.....#.#.#....#.######......#...........
...................................................................................................................................

View file

@ -1,11 +0,0 @@
...........
.....###.#.
.###.##..#.
..#.#...#..
....#.#....
.##..S####.
.##..#...#.
.......##..
.##.#.####.
.##..##.##.
...........

View file

@ -1,127 +0,0 @@
defmodule AOC.Day20 do
# use AOC.Day, day: 20, input: "example"
use AOC.Day, day: 20
def parse_input(lines) do
modules =
lines
|> Enum.map(fn line ->
[name, destination_modules] = String.split(line, " -> ")
destination_modules = String.split(destination_modules, ", ")
case String.at(line, 0) do
"%" -> {String.trim_leading(name, "%"), {:flip_flop, destination_modules, :off}}
"&" -> {String.trim_leading(name, "&"), {:conjunction, destination_modules, %{}}}
_ -> {name, {:broadcast, destination_modules}}
end
end)
|> Enum.into(%{})
Enum.reduce(modules, modules, fn {module_name, module}, acc ->
module
|> elem(1)
|> Enum.reduce(acc, fn destination_name, acc ->
case Map.fetch(acc, destination_name) do
{:ok, {:conjunction, destination_names, states} = destination_module} ->
Map.put(
acc,
destination_name,
{:conjunction, destination_names, Map.put(states, module_name, :low)}
)
_ ->
acc
end
end)
end)
end
def press_button(modules) do
pulse_queue = :queue.new()
pulse_queue = :queue.in({:low, "broadcaster", "button"}, pulse_queue)
propagate_pulses(modules, pulse_queue, {0, 0})
end
def send_pulses(pulse_queue, pulse_strength, destination_names, from) do
Enum.reduce(destination_names, pulse_queue, fn destination_name, acc ->
:queue.in({pulse_strength, destination_name, from}, acc)
end)
end
def propagate_pulses(modules, pulse_queue, {low_count, high_count}) do
case :queue.out(pulse_queue) do
{:empty, _} ->
{modules, {low_count, high_count}}
{{:value, {pulse_strength, module_name, from}}, pulse_queue} ->
{modules, pulse_queue} =
case Map.fetch(modules, module_name) do
:error ->
{modules, pulse_queue}
{:ok, {:broadcast, destination_names}} ->
pulse_queue =
send_pulses(pulse_queue, pulse_strength, destination_names, module_name)
{modules, pulse_queue}
{:ok, {:flip_flop, destination_names, state}} ->
case pulse_strength do
:high ->
{modules, pulse_queue}
:low ->
case state do
:off ->
module = {:flip_flop, destination_names, :on}
pulse_queue =
send_pulses(pulse_queue, :high, destination_names, module_name)
{Map.put(modules, module_name, module), pulse_queue}
:on ->
module = {:flip_flop, destination_names, :off}
pulse_queue = send_pulses(pulse_queue, :low, destination_names, module_name)
{Map.put(modules, module_name, module), pulse_queue}
end
end
{:ok, {:conjunction, destination_names, state}} ->
state = Map.put(state, from, pulse_strength)
modules = Map.put(modules, module_name, {:conjunction, destination_names, state})
all_high? = state |> Map.values() |> Enum.all?(&(&1 == :high))
pulse_queue =
if all_high? do
send_pulses(pulse_queue, :low, destination_names, module_name)
else
send_pulses(pulse_queue, :high, destination_names, module_name)
end
{modules, pulse_queue}
end
low_count = low_count + if pulse_strength == :low, do: 1, else: 0
high_count = high_count + if pulse_strength == :high, do: 1, else: 0
propagate_pulses(modules, pulse_queue, {low_count, high_count})
end
end
def part1(modules) do
{_, {lows, highs}} =
Enum.reduce(1..1000, {modules, {0, 0}}, fn _, {modules, {low_acc, high_acc}} ->
{modules, {low, high}} = press_button(modules)
{modules, {low_acc + low, high_acc + high}}
end)
lows * highs
end
def part2(_input) do
"TODO"
end
end

View file

@ -1,67 +0,0 @@
defmodule AOC.Day21 do
# use AOC.Day, day: 21, input: "example"
use AOC.Day, day: 21
def parse_input(lines) do
map =
lines
|> Enum.with_index()
|> Enum.flat_map(fn {line, y} ->
line
|> String.to_charlist()
|> Enum.with_index()
|> Enum.map(fn {tile, x} -> {{y, x}, tile} end)
end)
|> Enum.into(%{})
start_position =
map
|> Enum.find(fn {_, tile} -> tile == ?S end)
|> elem(0)
{Map.put(map, start_position, ?.), start_position}
end
def walk(map, start_position, steps) do
map
|> do_walk(start_position, steps)
|> Enum.count()
end
def do_walk(map, position, _) when not is_map_key(map, position), do: []
def do_walk(map, position, _) when :erlang.map_get(position, map) == ?#, do: []
def do_walk(_map, position, 0), do: [position]
def do_walk(map, {y, x} = position, steps_left) do
case :ets.lookup(:steps_memo, {position, steps_left}) do
[] ->
reachable =
[{y - 1, x}, {y, x + 1}, {y + 1, x}, {y, x - 1}]
|> Enum.flat_map(fn neighbor_position ->
do_walk(map, neighbor_position, steps_left - 1)
end)
|> Enum.uniq()
:ets.insert(:steps_memo, {{position, steps_left}, reachable})
reachable
[{_, reachable}] ->
reachable
end
end
def part1({map, start_position}) do
:ets.new(:steps_memo, [:named_table])
map
|> walk(start_position, 64)
|> IO.inspect()
"TODO"
end
def part2(_input) do
"TODO"
end
end