DEV Community

loading...

Discussion on: Advent of Code 2020 Solution Megathread - Day 6: Custom Customs

Collapse
vncz profile image
Vincenzo Chianese • Edited

I've solved this using Clojure for the sake of. It seems to be the shortest one so far.

(ns day6 (:require [clojure.string :refer [split]]
                   [clojure.set :refer [intersection]]))

(def input (-> "./day6input.txt"
               (clojure.core/slurp)
               (split #"\n\n")))

(def any-answers (->> input
                      (map #(re-seq #"\w" %))
                      (map set)
                      (reduce #(+ %1 (count %2)) 0))) ; Part 1

(def all-answers (->> input
                      (map #(split % #"\n"))
                      (map #(map (fn [x] (set (clojure.core/char-array x))) %))
                      (map #(apply intersection %))
                      (reduce #(+ %1 (count %2)) 0))) ; Part 2
Enter fullscreen mode Exit fullscreen mode