bjorng
Erlang Core Team
Advent of Code 2025 - Day 6
defmodule Day06 do
def part1(input) do
input
|> Enum.map(fn line ->
line
|> String.split(" ", trim: true)
|> Enum.map(fn token ->
case Integer.parse(token) do
:error -> String.to_atom(token)
{n, ""} -> n
end
end)
end)
|> transpose
|> Enum.map(fn column ->
operator = List.last(column)
Enum.drop(column, -1)
|> Enum.reduce(&(eval(operator, &1, &2)))
end)
|> Enum.sum
end
def part2(input) do
operators = List.last(input)
spaces = count_spaces(String.to_charlist(operators))
operators = operators
|> String.to_charlist
|> Enum.filter(&(&1 !== ?\s))
|> Enum.map(&List.to_atom([&1]))
input
|> Enum.drop(-1)
|> Enum.map(fn line ->
String.to_charlist(line)
|> split_line(spaces)
end)
|> transpose
|> Enum.zip(operators)
|> Enum.map(fn {column, operator} ->
column
|> transpose
|> Enum.map(fn column ->
column
|> Enum.filter(&(&1 !== ?\s))
|> List.to_integer
end)
|> Enum.reduce(&(eval(operator, &1, &2)))
end)
|> Enum.sum
end
defp split_line([], []), do: []
defp split_line(line, [n]) do
{number, []} = Enum.split(line, n + 1)
[number]
end
defp split_line(line, [n | ns]) do
{number, rest} = Enum.split(line, n)
[?\s | rest] = rest
[number | split_line(rest, ns)]
end
defp count_spaces([]), do: []
defp count_spaces([_op|rest]) do
{spaces, rest} = Enum.split_while(rest, &(&1 === ?\s))
[length(spaces) | count_spaces(rest)]
end
defp eval(operator, number1, number2) do
apply(Kernel, operator, [number1, number2])
end
defp transpose(list) do
Enum.zip_with(list, &Function.identity/1)
end
end
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
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
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
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First 10 of 21 Posts
Aetherus
Yet another easy puzzle.
Part 1
Part 2
Split the puzzle input into
[[char()]], then rotate left (= transpose then reverse).vkryukov
I’m using my
Arraymodule again:Array.colreturns a column as a list,Array.subarrayreturns a subarray with given indexes, andArray.from_listis a constructor that takes a list of lists.lkuty
hauleth
Setup
Part 1
Part 2
lud
Arf I wish I had thought to use String.to_integer before chunking!
Edit:
yes, that makes is much simpler:
I had a version of my first solution with chunk_while as well but I feel it makes everything harder to read.
sevenseacat
I don’t love the code I wrote today - all the work was in parsing the input into the shape I wanted. Lots of string manipulations, list transposing, and messy stuff.
https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2025/day06.ex
Also, this is the first time this year I’ve been confused at the speed of my solution, did some profiling, and found out that all the time was totally not where I expected it to be!
dompdv
Same comment. Most of the job is done in the parsing, accumulate data in Map, to get a data structure that makes the main algorithm I simple.
But I still wonder how to make it nice.
rvnash
Anyone else feel there was little “fun” in todays problem? I enjoy problems when there is a challenging data structure or algorithmic obstacle to surmount. This seemed like a lot of persnickety busywork.
BartOtten
Yeah, as I have a time limit I only made Part 1, Part 2 I only drafted in pseudo code: taking largest number in a row (A), then chunk the 'row string’ with number A to have the numbers including whitespace. From there on it’s just ‘grid’ing again.
Part 1
BartOtten
Reading the second problem on the iPhone makes it more challenging to understand how their math works… (see the alignment of numbers)