AoC/2022/day03/day03.hs
2022-12-03 16:51:46 +01:00

18 lines
475 B
Haskell

import Data.List
import Data.List.Split
import Control.Arrow
main :: IO ()
main = do
input <- lines <$> readFile "input"
print $ (day3a &&& day3b >>> sum *** sum) input
day3a :: [String] -> [Int]
day3a = map $ convert . uncurry intersect . (nub *** nub) . (flip splitAt <*> flip div 2 . length)
day3b :: [String] -> [Int]
day3b = map (convert . foldl1 intersect) . chunksOf 3
convert :: String -> Int
convert = (\x->if x>90 then x - 96 else x - 38) . fromEnum . head