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
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)
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)