r/adventofcode • • Dec 17 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 17 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It

  • 5 days remaining until the submission deadline on December 22 at 23:59 EST
  • Full details and rules are in the Submissions Megathread

--- Day 17: Conway Cubes ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:13:16, megathread unlocked!

34 Upvotes

657 comments sorted by

View all comments

Show parent comment

1

u/DFreiberg Dec 17 '20

You're probably right - CellularAutomaton[] was the first thing I checked, but every time I've tried using it in the past I've been burned by the fact that it assumes that inputs wrap 'wrap around' rather than having a definite edge, or being able to expand indefinitely (though as I type this I've just realized that I could make the array large enough to begin with that no wrapping occurs, just like I did with SparseArray[] today).

Plus, you'd have to generate either the rule number or the full list of substitutions, and there's usually a twist of some kind in part 2, and often CellularAutomaton[] can't scale, or can't easily scale, to fit the problem; day 11 of this year being a perfect example. Between it all I've just never found it easier (aside from the 2D case) to use the built-ins for this than to just make my own and be done with it.

That said, what kind of input is your code expecting? I tried filling it with mine (replaced by 1s and 0s, of course) and got a syntax error from CellularAutomaton[] about the initial condition specifications that I don't quite understand.

2

u/optoburger Dec 18 '20

Yeah, truth be told I had to do a surprising amount of wrestling to get what's there to work. I'm not particularly familiar with either Mathematica or CellularAutomaton[], so no doubt there are more graceful ways to specify the rule and neighbourhood.

As to the input, just a multidimensional list, for example here's the test input padded in a large enough space not to hit the boundary.

input = CenterArray[{{0, 1, 0},
                     {0, 0, 1},
                     {1, 1, 1}},
                    {20, 20, 20}];

1

u/DFreiberg Dec 18 '20

Check out /u/Adereth's solution here: https://old.reddit.com/r/adventofcode/comments/keqsfa/2020_day_17_solutions/gg5ipiz/

He found an option that lets you bypass specifying the rule number, getting the entire problem in a one-liner.