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

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
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews