bjorng
Erlang Core Team
Part 1 took much more time than part 2. I started out by reusing my grid parsing function from day 4 and start coding before I had fully understood the splitting rules and how to count splits. It ended up in a mess.
After having finished part 2, I rewrote part 1 using the new parsing routine that I wrote for part 2.
defmodule Day07 do
def part1(input) do
{start, splitters} = parse_splitters(input)
beams = [start]
split_beams(beams, splitters, 0)
end
defp split_beams(_beams, [], num_splits), do: num_splits
defp split_beams(beams, [splits | splitters], num_splits) do
{beams, num_splits} = split_beams(beams, splits, [], num_splits)
split_beams(beams, splitters, num_splits)
end
defp split_beams([], _splitters, new, num_splits) do
{Enum.uniq(new), num_splits}
end
defp split_beams([column | beams], splits, new, num_splits) do
case Enum.member?(splits, column) do
true ->
new = [column - 1, column + 1 | new]
split_beams(beams, splits, new, num_splits + 1)
false ->
new = [column | new]
split_beams(beams, splits, new, num_splits)
end
end
def part2(input) do
{start, splitters} = parse_splitters(input)
{timelines, _} = count_timelines(start, splitters, %{})
timelines
end
defp count_timelines(column, splitters, worlds) do
key = {column, length(splitters)}
case worlds do
%{^key => timelines} ->
{timelines, worlds}
%{} ->
{timelines, worlds} = count_timelines_split(column, splitters, worlds)
{timelines, Map.put(worlds, key, timelines)}
end
end
defp count_timelines_split(_column, [], worlds) do
{1, worlds}
end
defp count_timelines_split(column, [splits | splitters], worlds) do
case Enum.member?(splits, column) do
true ->
{timelines1, worlds} = count_timelines(column - 1, splitters, worlds)
{timelines2, worlds} = count_timelines(column + 1, splitters, worlds)
timelines = timelines1 + timelines2
{timelines, worlds}
false ->
count_timelines(column, splitters, worlds)
end
end
defp parse_splitters(input) do
splitters = input
|> Enum.map(fn line ->
String.to_charlist(line)
|> Enum.with_index
|> Enum.flat_map(fn {char, col} ->
case char do
?. -> []
?S -> [{:start, col}]
?^ -> [col]
end
end)
end)
[[{:start, start}] | splitters] = splitters
{start, splitters}
end
end
EDIT: Further simplified part 1 by removing vestiges of my messy first solution.
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 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lkuty
dompdv
Simplified after doing Part2 because Part2 solves also Part1.
vkryukov
Nice problem - you can solve both part simultaneously if you keep track of everything.
hauleth
Parse
Part 1
Part 2
EDIT
I decided to draw the resulting image
lud
Part 1 took me more time too
sevenseacat
I have no idea what the algorithm is called here but I think I’ve done something very similar in previous puzzles - instead of adding
|to my grid map, add the number of beams that have reached this point. Then at the end, add up all of the numbers on the bottom row.https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2025/day07.ex
Wasted about half an hour debugging the part 2 example because one of my clauses was wrong - I forgot to increment when a beam overlaps another beam
rvnash
I think it’s called “Pascal’s Triangle”, dunno maybe I’m wrong. Anyway, I naively did Part 2 and of course it doesn’t complete in the age of the universe. So, decided to keep track of both timelines and tachyons in one pass. Went much better. Used MapSet and Map to speed lookups. Fun day!
Edit: It is Pascal’s Triangle except with the twist that the tree doesn’t split necessarily evenly on each level.
newton-peixoto
Part 01 was pretty straightforward, but in Part 02 I had difficulty parsing the input into an adjacency list. On my first try, I ran a pure DFS, which of course didn’t finish. I had to optimize it using memoization which took some time
https://github.com/newton-peixoto/advent-of-code/blob/main/2025/livebooks/day-07.livemd
sevenseacat
oh I’ve heard of that! Cheers
vkryukov
Very elegant solution. I realized, after looking at it, that I shouldn’t even have to check for boundary conditions, as by design the beams cannot go outside.