sasajuric

sasajuric

Author of Elixir In Action

Note: This topic is to talk about Day 12 of the Advent of Code.

For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.

Showing Posts 1 to 9

sasajuric

sasajuric OP

Author of Elixir In Action

My solution is here.

Part 1 was pretty straightforward. I built a map of rules, and then used a bit of binary pattern matching to move to the next state.

In part 2 it really helped me that I did AoC last year. As soon as I saw it, I knew that there had to be a cycle. I did a quick experiment, and found out that the plants converge to the stable state pretty soon. In that state, the plants relative positioning doesn’t change, but they gradually move in one direction.

I briefly thought about solving this special case, but I wasn’t quite happy with that, because I thought there might exist a more general situation with larger cycles. Therefore, I wrote a more complex recursion which caches pattern transitions, and can handle the cycle of any length.

mkasztelnik

mkasztelnik

My solution is here - cleaning of the generation head and tail allows me to discover the cycle.

JEG2

JEG2

Author of Designing Elixir Systems with OTP

Here’s my solution to Day 12:

https://github.com/JEG2/advent_of_code_2018/blob/master/day_12/subterranean_sustainability.exs

I also found the cycle and quit there.

Here’s a video of the creation of this code (good for 14 days):

snewcomer

snewcomer

Phoenix Core Team

Too much appending to lists in this solution. Need to optimize still for part 2

https://github.com/snewcomer/advent-of-code-elixir/blob/master/day12/lib/day12.ex

theshank

theshank

Thanks for sharing your solutions, I am learning tons by reading your code! On line 10 of the solution here, it looks like a declaration of the function without any body. Why is this separate and why not put this in the definition at line 14 itself? Thanks in advance :slight_smile:

sasajuric

sasajuric OP

Author of Elixir In Action

That function has multiple clauses (in this case two - in lines 10 and 12 respectively, and it also has a default third argument. In this case, a separate bodyless function clause is needed to declare defaults. This is explained in the def documentation.

theshank

theshank

Thanks !

alvises

alvises

Hi James, do you still have the original videos? It would be great you could upload them somewhere - they are a great learning resource!

JEG2

JEG2

Author of Designing Elixir Systems with OTP

I don’t. Sorry.

— All posts loaded —

Where Next? Top

Trending in Challenges Top

Other Trending Topics Top

GenericJam
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
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews