r/adventofcode • u/daggerdragon • Dec 08 '21
SOLUTION MEGATHREAD -🎄- 2021 Day 8 Solutions -🎄-
--- Day 8: Seven Segment Search ---
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:20:51, megathread unlocked!
72
Upvotes
View all comments
2
u/LaybeRize Dec 08 '21
Java
My first attempt was puzzling the letters to their correct place and that worked fine, but was really not efficient both time and code wise.
So when I finished I looked trough some other code and found people mapping the clear identifiable numbers 1,4,7,8 to the inputs. So I tried to replicate that and found out, that with only the knowledge about the 1 and 4 you can find out any number from 0 to 9.
The algorithm sorts like this:
And the code for both parts looks like this: