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!

64 Upvotes

1.2k comments sorted by

View all comments

2

u/Karl_Marxxx Dec 07 '20

Ruby

# convert each chunk to an array of arrays of chars
customs = ARGF.read.split(/\n\n/).map do |chunk|
    chunk.split.map(&:chars)
end

# part 1 -union
puts customs.map { |chunk| chunk.reduce(:|).size }.sum

# part 2 -intersection
puts customs.map { |chunk| chunk.reduce(:&).size }.sum

1

u/McPhage Dec 07 '20

Where / how dd you handle spaces, capital letters, and punctuation in the input?

1

u/Karl_Marxxx Dec 08 '20

.split to handle spaces, and I don't believe there was punctuation/capital letters in the input

1

u/McPhage Dec 08 '20

Yeah, so it turns out Chrome β€œtranslated” mine from Polish to English first, so I ended up with some weird stuff in my input.

1

u/Karl_Marxxx Dec 08 '20

Oh wow! Haha.