hauleth
Guidance Counsellor
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (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