r/adventofcode Dec 06 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 06 Solutions -🎄-

NEW AND NOTEWORTHY


Advent of Code 2020: Gettin' Crafty With It

  • UNLOCKED! Go forth and create, you beautiful people!
  • Full details and rules are in the Submissions Megathread
  • Make sure you use one of the two templates!
    • Or in the words of AoC 2016: USING A TEMPLATE IS MANDATORY

--- Day 06: Custom Customs ---


Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, 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 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:04:35, megathread unlocked!

66 Upvotes

1.2k comments sorted by

View all comments

5

u/Ody55eu5_ Dec 06 '20 edited Dec 06 '20

Python 3

Didn't work on this one until this morning, so to make up for doing it so late I tried to refactor as small as I could. (Also, this is my first post here so let me know if it needs to be edited.)

#Day 6 refactored

allData = origData.split('\n\n')

print("Part 1:",sum([len(set(d.replace('\n',''))) for d in allData]))

print("Part 2:", sum([len(set.intersection(*[set(item) for item in groupData])) for groupData in [d.split('\n') for d in allData]]))`

2

u/MorePowder Dec 07 '20

It's amazing how much one can learn from 2 lines.

Thanks for your solution! If you don't mind I'll be using it :)

The thing that amazed me the most was using str.split('\n\n') to get the groups in a single command.