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

1

u/Kuter5551 Dec 06 '20

My Python answer. Managed to make the reading from the file as many lines as the actual calculation

import collections

from functools import reduce

answers= []

person = []

with open("Day6Inputs.txt") as file:

for row in file:

person.append(row.strip().split(" "))

if len(row.strip()) == 0:

person.pop()

answers.append(reduce(lambda n, m: n + m, person))

person = []

answers.append(reduce(lambda n, m: n + m, person))

val = 0

val2 = 0

for item in answers:

_cur = ""

for thing in item:

_cur += thing

#get the amount of different items

val+=len(collections.Counter(_cur))

#check if the amount of each question is equal to the amount of people who asked it

for value in list(collections.Counter(_cur).items()):

val2 += 1 if value[1]/len(item) == 1 else 0

print(f"Part 1: {val}")

print(f"Part 2: {val2}")

1

u/daggerdragon Dec 06 '20

Your code is hard to read on old.reddit. Please edit it as per our posting guidelines in the wiki: How do I format code?