sasajuric

sasajuric

Author of Elixir In Action

Advent of Code - Day 12

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.

Most Liked

sasajuric

sasajuric

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.

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):

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:

Where Next?

Popular in Challenges Top

cblavier
Hey there :wave: No magic or algorithmic finesse today, I just finished the challenge and I my code is quite slow (1sec for part1, 3se...
New
lud
At first I was scared but I found is a simple way to compute the sides. defmodule AdventOfCode.Solutions.Y24.Day12 do alias AdventOfCo...
New
bjorng
This topic is about Day 16 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums): https://adve...
New
bjorng
Here is my solution: https://github.com/bjorng/advent-of-code-2021/blob/77bdef7a51b428b58ffb4ab76f540901e636f841/day12/lib/day12.ex
New
kwando
Phew, this one took a while to get right. My naive attempts was way to slow so I reached for Dijkstras shortest path algorithm.. and that...
New
bjorng
This topic is about Day 2 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums): https://adven...
New
cblavier
Hi, there :wave: Today, I felt it was way more challenging! I went through part2 thanks to Agent based memoization (without memoization ...
New
code-shoily
Just did part 1. Part 2 seems to be demanding too much of my reading time so will get to that after I am done with some chores. Oh here ...
New
adamu
Probably not the most efficient implementation, because part 1 took >1 ms and part 2 >4ms, but the code was simple enough. def p...
New
lud
Hello everyone! This year is going to be shorter, but the difficulty will grow faster. Today I already feel that this is not standard “D...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement