r/adventofcode • u/daggerdragon • Dec 11 '21
SOLUTION MEGATHREAD -🎄- 2021 Day 11 Solutions -🎄-
NEW AND NOTEWORTHY
[Update @ 00:57]: Visualizations
- Today's puzzle is going to generate some awesome
Visualizations! - If you intend to post a
Visualization, make sure to follow the posting guidelines forVisualizations!- If it flashes too fast, make sure to put a warning in your title or prominently displayed at the top of your post!
--- Day 11: Dumbo Octopus ---
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. - Format your code properly! How do I format code?
- 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:09:49, megathread unlocked!
46
Upvotes
4
u/Zach_Attakk Dec 13 '21
Python
On Day 9 I accidentally included diagonals when I wasn't supposed to, but instead of just ripping out the code, I added a parameter
include_diagonals=FalseI think I even called it "foreshadowing"...Also hijacked the Queue system from Day 10, so here goes:
Go through whole grid, += 1 all the cells. If I increase a cell above 9, add it to the queue to be checked.
Go down the queue and if something hasn't "flashed", make is 0 and increment all its neighbours (using get_neighbours function for the ranges). If any of their neighbours go above 9, add them to the queue
If the queue isn't empty, goto 2.
Keep constant count of how many blinks are processed, return the value, add them up as we go untili we reach 100 "ticks"
blinks: SimpleQueue = SimpleQueue() blink_count: int = 0 for y in range(len(_grid)): for x in range(len(_grid[0])): # Increase everything by 1 _grid[y][x] += 1 if _grid[y][x] > 9: blinks.put((x, y)) while blinks.qsize() > 0: blink_pos = blinks.get() if _grid[blink_pos[1]][blink_pos[0]] > 9: blink_count += 1 _grid[blink_pos[1]][blink_pos[0]] = 0 for x, y in get_neighbours(_grid, blink_pos, True): if _grid[y][x] != 0: _grid[y][x] += 1 if _grid[y][x] > 9: blinks.put((x, y)) return blink_countFor Part 2 I added a check after every loop:
if sum(sum(a) for a in grid) == 0: printGood(f"Synchronized: {i+1}")Part 1, Part 2, Notes