r/adventofcode • u/daggerdragon • Dec 11 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 11 Solutions -🎄-
Advent of Code 2020: Gettin' Crafty With It
11 days remaining until the submission deadline on December 22 at 23:59 EST
Full details and rules are in the Submissions Megathread
--- Day 11: Seating System ---
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:14:06, megathread unlocked!
50
Upvotes
4
u/landimatte Dec 11 '20
Common Lisp
Notes for the reader:
seat coordinates are COMPLEX numbers
the layout is a HASH-TABLE (I initially thought about using an 2D array, but figured a HASH-TABLE would save me from using ARRAY-IN-BOUNDS-P all over the place)
Part 1: count adjacent
#s -- the nice thing about using a HASH-TABLE, is that I don't have to worry about going off the grid (i.e.(gethash (+ seat d) layout #\.))Part 2: recursively move in the neighboring direction (COMPLEX numbers for the win again) until you find
#,L, or fall off the gridNotes for the future self:
don't spend too much time thinking about what you think the best implementation is (2d array? 1d array + major index? hash-table?) -- just try one and see
read the damn problem -- Also, people seem to be more tolerant than you expected: it now takes five or more visible occupied seats for an occupied seat to become empty (rather than four or more from the previous rules).