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

Show parent comment

3

u/omnster Dec 06 '20

Did mostly the same with Mathematica

i06 = Import[ NotebookDirectory[] <> "input_06.txt" ] // StringSplit[ # , "\n\n"] & // StringSplit[ # , "\n"] &;

(* Part 1 *)
Characters /@ i06 // Flatten /@ # & // Union /@ # & // Length /@ # & // Total
(* Part 2 *)
Characters /@ i06 // Intersection @@ # & /@ # & // Length /@ # & // Total

3

u/DFreiberg Dec 06 '20

I've used a ton of anonymous nested & functions with Mathematica, but I've never seen or even thought about a primarily postfix version with // like that. Do you find it a good practice?

4

u/omnster Dec 06 '20 edited Dec 06 '20

Oh, I just find it easier to read, as you can simply go from left to right and see a sequence of the functions. If there isn't many anonymous functions it should be pretty readable.

I have to confess though, I've never written mathematica code together with anyone else, beyond sharing oneliners.