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
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
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
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #performance










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