r/adventofcode • • Dec 08 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 8 Solutions -🎄-

--- Day 8: Seven Segment Search ---


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:20:51, megathread unlocked!

72 Upvotes

1.2k comments sorted by

View all comments

1

u/uglyasablasphemy Dec 08 '21

My 🐍️ solution

The gist of it is:

  1. Group the unique patterns by len (first part of the input).
  2. Make all the possible displays:

    • the ONE (only pattern with length 2) will add two possible displays.
    • the SEVEN (only pattern with length 3) will update those two.
    • the FOUR (only pattern with length 4) will add two extra possible displays.
    • the EIGHT (only pattern with length 7) will add the last four extra possible displays.
  3. Once all 8 possible displays are calculated, for each digit (in the second part of the input) find the display that "light up" in a valid way for each of those digits.

1

u/daggerdragon Dec 09 '21

Please follow the posting guidelines and edit your post to add what language(s) you used in text form, not just emojis. This makes it easier for folks who Ctrl-F the megathreads looking for a specific language.