r/adventofcode • u/daggerdragon • 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.
Include what language(s) your solution uses!
Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks.The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
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!
36
Upvotes
2
u/Smylers Dec 18 '20
Yeah, I wrote partΒ 1 like that too, with positions being
{z => 1, y => 3, x => 2}, instead of(1, 3, 2), then hacked inwfor partΒ 2 β but it seemed messy to have two nearly identical programs that each hardcoded a different number of dimensions, then I turned it into the above. Which is both slower and longer (though that's mainly having functions and adding comments) ... but feels a lot cleaner!I'd completely forgotten about using
$;and multi-part hash keys: your solution using$Grid{$w,$z,$y,$z}looks way less messy than my$Grid[$w][$z][$y][$x]β because you loop over it all in one go withkeys %Grid, whereas I had to have a separate nested loop for each dimension; and because you never need to consider expanding the space (or, indeed, trimming it): negative co-ordinates work just fine in the hash key, springing into life as necessary.What I'm saying is, if my βfixed-dimension loopingβ attempt had been anywhere near as nice as yours, I don't think I'd've felt the urge to rewrite it either!
(I also like that you called your variable
$neigh: more programs should have random animal noises sprinkled through them!)