AoC2018/Day02/Part1.hs

15 lines
482 B
Haskell
Executable File

#! /usr/bin/env stack
-- stack --resolver lts-12.20 --install-ghc script
module Main where
import Control.Arrow ((&&&))
import Data.List (group, sort)
main :: IO ()
main = interact $ show . \input ->
let codes = lines input :: [[Char]]
counts = map (map (head &&& length) . group . sort) codes :: [[(Char, Int)]]
twos = length $ filter (any ((== 2) . snd)) counts
threes = length $ filter (any ((== 3) . snd)) counts
in (twos, threes, twos * threes)