{-# Language QuasiQuotes #-}
{-|
Module      : Main
Description : Day 6 solution
Copyright   : (c) Eric Mertens, 2020
License     : ISC
Maintainer  : emertens@gmail.com

<https://adventofcode.com/2020/day/6>

-}
module Main (main) where

import Advent.Format (format)
import Data.List (intersect, union)

-- |
-- >>> :main
-- 6273
-- 3254
main :: IO ()
IO ()
main =
  do [[[Char]]]
inp <- [format|2020 6 (%s%n)*&%n|]
     Int -> IO ()
forall a. Show a => a -> IO ()
print ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (([Char] -> [Char] -> [Char]) -> [Char] -> [[Char]] -> [Char]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr [Char] -> [Char] -> [Char]
forall a. Eq a => [a] -> [a] -> [a]
union []   ([[Char]] -> [Char]) -> [[[Char]]] -> [Char]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [[[Char]]]
inp))
     Int -> IO ()
forall a. Show a => a -> IO ()
print ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (([Char] -> [Char] -> [Char]) -> [[Char]] -> [Char]
forall a. (a -> a -> a) -> [a] -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 [Char] -> [Char] -> [Char]
forall a. Eq a => [a] -> [a] -> [a]
intersect ([[Char]] -> [Char]) -> [[[Char]]] -> [Char]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [[[Char]]]
inp))