bjorng
Erlang Core Team
Here is my solution for day 1 of Advent of Code:
defmodule Day01 do
def part1(input) do
all = parse(input)
{first, second} = Enum.unzip(all)
Enum.zip([Enum.sort(first), Enum.sort(second)])
|> Enum.map(fn {a, b} ->
abs(a - b)
end)
|> Enum.sum
end
def part2(input) do
all = parse(input)
{first, second} = Enum.unzip(all)
frequencies = Enum.frequencies(second)
first
|> Enum.map(fn n ->
n * Map.get(frequencies, n, 0)
end)
|> Enum.sum
end
defp parse(input) do
input
|> Enum.map(fn line ->
{first, line} = Integer.parse(line)
line = String.trim(line)
{second, ""} = Integer.parse(line)
{first, second}
end)
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)
code-shoily
I did it in F# and now that I see your Elixir code, mine is exactly the same code (in a different language lol)
The three spaces was this years twone for me and cost me a minute.
cblavier
Happy Advent Of Code everyone!

Part1:
Part2:
woojiahao
Pretty fun despite it’s simplicity, but the prompts are getting looong:
Github: aoc/lib/aoc/y2024/day_1.ex at main · woojiahao/aoc · GitHub (made a whole bunch of utility modules and functions from past years, to reduce code duplication)
pehbehbeh
Here are my solutions using Livebook:
https://github.com/pehbehbeh/adventofcode/blob/main/2024/01.livemd
lud
Starting very simple, but Elixir shines
It’s basically @bjorng 's solution.
sevenseacat
It’s the most wonderful time of the year!
https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2024/day01.ex
egze
Part 1:
Part 2:
dimitarvp
Are we not supposed to also include code for opening and reading the input from a file? Or we can opt to just put it in a module attribute and parse that?
egze
Well, I used KinoAOC — KinoAOC v0.1.7 for Livebook, and it binds the input to
puzzle_inputautomaticallywoojiahao
I made my own utility modules and functions because I’ve been using Elixir for the past 3-4 AoCs so I’ve accumulated use cases. The goal of posts should be the actual solution, it’s less important where the input comes from!