bjorng
Erlang Core Team
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
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
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
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










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