hauleth
Graph traversals
Parse
graph =
puzzle_input
|> String.split("\n", trim: true)
|> Map.new(fn <<from::binary-3>> <> ": " <> rest ->
{from, String.split(rest)}
end)
Implementation
defmodule Servers do
def paths(graph, from, to), do: paths(graph, from, to, [from])
defp paths(_graph, to, to, acc), do: [Enum.reverse(acc)]
defp paths(graph, from, to, acc) do
if next = graph[from] do
Stream.flat_map(next, &paths(graph, &1, to, [&1 | acc]))
else
[]
end
end
def paths_through(graph, from, to, required),
do: path_through(graph, from, to, MapSet.new(required), %{})
defp path_through(_graph, to, to, required, memo),
do: {if(Enum.empty?(required), do: 1, else: 0), memo}
defp path_through(graph, from, to, required, memo) do
state = MapSet.delete(required, from)
with :error <- Map.fetch(memo, {from, state}),
{:ok, next} <- Map.fetch(graph, from) do
{sum, memo} =
Enum.reduce(next, {0, memo}, fn n, {sum, acc} ->
{c, next_acc} = path_through(graph, n, to, state, acc)
{c + sum, next_acc}
end)
{sum, Map.put(memo, {from, state}, sum)}
else
:error -> {0, memo}
{:ok, val} -> {val, memo}
end
end
end
Part 1
Servers.paths(graph, "you", "out") |> Enum.count()
Part 2
Servers.paths_through(graph, "svr", "out", ["dac", "fft"])
|> elem(0)
Trending in Challenges
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











Showing Posts 1 to 6- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
lud
A similar solution but I divided the work in multiple steps:
count(svr -> fft) * count(fft -> dac) * count(dac -> out)Edit: simplified the parse, taking inspiration from hauleth’s
antoine-duchenet
The quickest day for me until now, which is surprising for day 11/12:
Pretty similar to the solutions above, except that I use my
Performance.memoizehelper instead of the usualcache/memoMap. I takes ~5ms to run on my machine for part 2.sevenseacat
Sad to think it’ll be over tomorrow
Guess I’ll have to amuse myself in the rest of December by revisiting old puzzles I never solved!
Part 1 was super straightforward - this is a directed graph, and the two nodes are pretty close together.
For part 2, the nodes are not close together, they’re at opposite ends of the graph
So I used a similar BFS approach to the puzzle with counting the timelines in the beam splitter (day 7) though this code ended up being a lot nicer! I split it into three parts -
svrtofft,ffttodac, and thendactoout, multiplying the numbers together at the end.https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2025/day11.ex
newton-peixoto
Pretty much copy and paste my solution from day 07
https://github.com/newton-peixoto/advent-of-code/blob/main/2025/livebooks/day-11.livemd
bjorng
lkuty