Aetherus
This topic is about the Advent of Code 2021 - Day 4.
Thanks to @bjorng , we now have a new Private Leaderboard.
The entry code is:
370884-a6a71927
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)
bjorng
It is already getting a bit trickier. Here is my solution:
https://github.com/bjorng/advent-of-code-2021/blob/66f5958a3a2fa3043c2b18d5b9b306ce52c742d7/day04/lib/day04.ex
Aetherus
Today I tried LiveBook on the new Elixir 1.13.0, and accidentally deleted my part 1 code, so I just post my part 2:
It feels a little bit tricky implementing a modification-based algorithm in an immutable way.
Aetherus
Sorry for posting twice. There was a network issue when I tried to edit my answer, and I don’t know how to delete one.
code-shoily
It’s starting to get difficult already, at least from the perspective of Elixir. It’s difficult to come up with a solution fast that is mutation and early return friendly on a matrix like data.
Aetherus
I usually use
%{{x, y} => val}to represent a matrix, but for today’s challenge, I recognized that I need to look up{x, y}by values, so I swapped the keys and the values.code-shoily
Here I am thinking the opposite direction, I am thinking
%{value => {row, col}}whererow = div(idx, 5)andcol = rem(idx, 5). That way I can just remove the value into a bucket ofrowlist, collistas I move forward. But it’s feeling slightly weird and verbose.Update: Seems like you’re doing the same thing. Sorry, brain’s not keeping up with eyes lol.
code-shoily
Ah, finally got the first one right, also, I got to use the new
Map.mapUPDATE: Did both parts, Part 2 was quicker to implement, but I don’t have a good feeling about this code for some reason.
princemaple
https://github.com/princemaple/aoc/blob/main/2021/day4.exs
wasi0013
My solution: y2021/day_04.ex
Klohto
I’m already ashamed by posting this horrible Part 1.
At this point, I’ll have to switch to normal function definitions because it’s becoming a spaghetti mess with anons and it’s just Day 4.
Don’t ask how I did Part 2, I have to clean both solutions up first.
It’s a challenge trying to do this in an immutable way.