bjorng

bjorng

Erlang Core Team

Advent of Code 2021 - Day 18

This topic is about Day 18 of the Advent of Code 2021.

We have a private leaderboard (shared with users of Erlang Forums):

https://adventofcode.com/2021/leaderboard/private/view/370884

The entry code is:
370884-a6a71927

Most Liked

ramuuns

ramuuns

soo much tedious debugging of recursion, but I love the fact that the parsing is pretty much just a Code.eval_string

also I’m pretty sure I shot myself in the foot for having each node be a {depth, [left, right]} as I think this was making some of the recursion annoying and it was easy to accidentally create the node wrong and whatnot.

Anyhow, both parts run in about 100ms - aoc/day-18.ex at 1542d38365d74533b324c4f790699767ce81b8e9 · ramuuns/aoc · GitHub

Update:
since I hate myself and apparently “enjoy spending a few more hours debugging recursion”, I implemented another version, that runs slightly faster where each node is a {depth, needs_split?, [left, right]}. Besides the ~10% perf improvement, it does slightly simplify the splitting operation at the cost of having to keep track if a node (or any of its children) need to be split. Code for the “improved” version: aoc/day-18.ex at 3419958dee43037aded833dc46c4fde183443add · ramuuns/aoc · GitHub

zevv

zevv

No sir, I did not at all like today’s puzzle sir. Every year there is at least one like those: too much text describing a tedious arbitrary process that’s a PITA to debug because you missed one of the many rules.

Anyway, I fought with a solution for too long where the numbers were stored as nested lists, but the recursion caused a pain behind my eyes. I fell back to just storing the numbers in a list, and exploding them by keeping track of a left and right carry that gets added to the next number to arrive. It suits nice with pattern matching, the end result is not too bad IMHO (even though some of the code looks more like Perl then Elixir), and fits in under a 100 lines,

bjorng

bjorng

Erlang Core Team

Here is my solution:

UPDATE: I’ve also implemented a solution in Erlang with a different internal representation that simplifies the explode operation.

Where Next?

Popular in Challenges Top

igorb
So… that’s it? Everyone is stuck on part 2? :slight_smile: I looked at Reddit hints and thought I probably wouldn’t have come up with the...
New
jkwchui
Monkeys fitted squarely as GenServers in my head. My initial problem was using cast instead of call; I imagine impolite monkeys slinging...
New
sb8244
Note: This topic is to talk about Day 10 of the Advent of Code 2019 . There is a private leaderboard for elixirforum members. You can jo...
New
bjorng
Note: This topic is to talk about Day 18 of the Advent of Code 2019. There is a private leaderboard for elixirforum members. You can joi...
New
Aetherus
This topic is about Day 15 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
New
groovyda
Today’s challenge for me was about using reduce: defmodule Prob5 do def move([[h1 | rest] = _list1, list2]) do [rest, [h1 | list2]...
New
shritesh
I mapped both the cards and every possible hand to numeric values and sorted them. In part 2 I could only think of replacing the jokers w...
New
bjorng
Note: This topic is to talk about Day 4 of the Advent of Code 2019. There is a private leaderboard for elixirforum members. You can join...
New
mattbaker
I’m having so much fun working on the “Protohackers” challenges, I never got into Advent of Code much but this has been amazing. The chal...
New
christhekeele
Setting this down for the night, as after a quick naive solve for quick part 1 I realize that part 2 is by design computationally expensi...
New

Other popular topics Top

josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39247 209
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35953 110
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I'm a nov...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement