{-# Language QuasiQuotes #-}
module Main where
import Advent (countBy, format)
import Data.List (sort, nub)
main :: IO ()
IO ()
main =
do [[[Char]]]
input <- [format|2017 4 (%s& %n)*|]
Int -> IO ()
forall a. Show a => a -> IO ()
print (([[Char]] -> Bool) -> [[[Char]]] -> Int
forall (f :: * -> *) a. Foldable f => (a -> Bool) -> f a -> Int
countBy [[Char]] -> Bool
forall a. Ord a => [a] -> Bool
allUnique [[[Char]]]
input)
Int -> IO ()
forall a. Show a => a -> IO ()
print (([[Char]] -> Bool) -> [[[Char]]] -> Int
forall (f :: * -> *) a. Foldable f => (a -> Bool) -> f a -> Int
countBy [[Char]] -> Bool
forall a. Ord a => [[a]] -> Bool
allUniqueModuloAnagrams [[[Char]]]
input)
allUnique :: Ord a => [a] -> Bool
allUnique :: forall a. Ord a => [a] -> Bool
allUnique [a]
x = [a]
x [a] -> [a] -> Bool
forall a. Eq a => a -> a -> Bool
== [a] -> [a]
forall a. Eq a => [a] -> [a]
nub [a]
x
allUniqueModuloAnagrams :: Ord a => [[a]] -> Bool
allUniqueModuloAnagrams :: forall a. Ord a => [[a]] -> Bool
allUniqueModuloAnagrams = [[a]] -> Bool
forall a. Ord a => [a] -> Bool
allUnique ([[a]] -> Bool) -> ([[a]] -> [[a]]) -> [[a]] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> [a]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> [a]
forall a. Ord a => [a] -> [a]
sort