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.
The Puzzle
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.
The Leaderboards
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.
Yesterday’s Languages
Updated 03:09PM 12/12/2020 PST.
Language | Count |
---|---|
JavaScript | 5 |
Rust | 2 |
Ruby | 2 |
C# | 1 |
C | 1 |
COBOL | 1 |
Elixir | 1 |
Merry Coding!
Top comments (14)
This one went surprisingly well! Still really fast, which I'm loving. And I got to make some more involved macros, which is fun.
Day11.h:
Day11.c:
COBOL, Friday night means I had time to do both parts.
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:
I used Haskell. Definitely not the most efficient or optimized solution:
Oops, forgot to post yesterday. Pleased with how this one turned out, especially the unit tests.
Part 1 and 2 js solution, toggle part2 to
true
orfalse
depending on your needsI'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 :(
python solution for both part 1 and 2
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:
Part 2:
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: