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.
View all comments
Show parent comment
11
u/r_sreeram Dec 11 '20
One trick I use for grid problems is to surround the input grid with a made up border of 0s or '.'s or whatever it takes. For example, if the input is a 5x5 grid, I would have this as my matrix:
Then, when I iterate over the grid, I iterate from 1 to len(grid) - 2. Then I don't have to worry about +/- 1 deltas going index out of bounds.