Today and yesterday are very different types of puzzles. This one is a variation on a staple of the AoC series: Conway's Game of Life.
In today’s puzzle, we're modeling seats on a ferry. Except that this ferry is looking like a 2D grid and these seats are looking like cells, and this puzzle is looking a bit like the Game of Life. Our job is to simulate seating and wait until things stabilize.
As always, this is the spot where I’ll plug any leaderboard codes shared from the community.
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Updated 03:09PM 12/12/2020 PST.
Top comments (14)
python solution for both part 1 and 2
Oops, forgot to post yesterday. Pleased with how this one turned out, especially the unit tests.
Bit late today as I had to do yesterday first, due to teaching commitments and just to tired to sit down at 10pm to work on it yesterday :-)
Anyway, my first solution, which I won't post here, was very (very) slow, using just lists. So after see looking at comments reddit replaced lists with Map, with the key being the 2D index, it worked out pretty well. Of course, it would have been a lost faster in Rust or C++, just to two arrays, one for the current step, and one for the next, updating in place, and simply switching each step. However I'm trying to do as many of these using Haskell, as most of my other days use Rust and C++ and it's been fun returning to Haskell after quite a while. I feel I've learnt a lot just over these last few days, which always sees like a good outcome. Enough chat, my solution:
COBOL, Friday night means I had time to do both parts.
This one went surprisingly well! Still really fast, which I'm loving. And I got to make some more involved macros, which is fun.
Part 1 and 2 js solution, toggle part2 to
falsedepending on your needs
I'm not sure about others but it took a long 4-5 seconds for it to compute part 1, 5-6 for part 2 and I'm very disappointed :(
I used Haskell. Definitely not the most efficient or optimized solution:
Lots of code in this one, TIL about creating my generative iterators in Rust. Made me feel smart :). Boring parsing code is redacted. Full stuff on: github.com/benwtrent/advent-of-cod...
OOP in Ruby; I enjoyed writing this!
Ruby. Initially assumed a toroidal grid and wasted a huge amount of time in the process. Part 1:
Well I had a little time while rewatching Buffy this evening with the kids and inspired by E. Choroba, I wrote a very (very) simple C++ program to generate an annimated GIF showing the process of set allocation. It uses the single header GIF library:
The input is a file which has the width and height on the first two lines, followed by the grid for each step. For example, the example given in the AOC description for today:
As the seats don't move, one can probably optimize the code by precomputing the neighbouring or visible seats, but waiting for 4 seconds was not boring enough for me to try it. So, I just count the number of adjacent or visible seats for each seat and then update the seating map.
I tried the problem with go.
Unfortunately I still have a runtime in total of round about 120ms.
Do you have any suggestions for a performance enhancement?