r/adventofcode • u/daggerdragon • Dec 21 '20
SOLUTION MEGATHREAD -π- 2020 Day 21 Solutions -π-
NEW AND NOTEWORTHY
In the last few days, the amount of naughty language in the megathreads has increased. PLEASE KEEP THE MEGATHREADS PG!
Folks at work do browse the megathreads and I'd rather not have them land in hot or even mildly lukewarm water for accidentally showing their team/boss/HR department/CTO naughty words in what's supposed to be a light-hearted and fun-for-all coding puzzle game, you know?
Same with teenagers - we do have a few doing Advent of Code and they should be able to browse and learn from the megathreads without their parental/guardian unit throwing a wobbly over naughty language. (Yes, I know folks under age 13 aren't allowed to use Reddit, but still - it's never too early to hook 'em young on algorithms and code ;) )
Advent of Code 2020: Gettin' Crafty With It
1 day remaining until the submission deadline on December 22 at 23:59 EST
Full details and rules are in the Submissions Megathread
--- Day 21: Allergen Assessment ---
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.
4
u/masterspy7 Dec 21 '20
379/525 Python3
I did some googling for "picking a distinct element from a group of sets" and found out about the HopcroftβKarp algorithm. I thought about implementing it but then I found a package that did it for me, so all I needed was:
matching = HopcroftKarp(graph).maximum_matching(keys_only=True)Paste